From 2f77bff21896026f8baa1edeabdebfcdc9209846 Mon Sep 17 00:00:00 2001 From: rushtong Date: Tue, 9 Jan 2024 16:07:51 -0500 Subject: [PATCH] cache doid responses in local storage --- src/libs/ontologyService.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/libs/ontologyService.js b/src/libs/ontologyService.js index b9e3380e7..482720c4c 100644 --- a/src/libs/ontologyService.js +++ b/src/libs/ontologyService.js @@ -1,6 +1,7 @@ import axios from 'axios'; -import { Notifications } from './utils'; -import { getOntologyUrl } from './ajax'; +import {Notifications} from './utils'; +import {getOntologyUrl} from './ajax'; +import {Storage as storage} from '../libs/storage'; export const OntologyService = { @@ -10,10 +11,17 @@ export const OntologyService = { } const baseURL = await getOntologyUrl(); const params = {id: obolibraryURL}; - try{ - let resp = await axios.get(`${baseURL}/search`, {params}); - return resp.data; - } catch(error) { + try { + const data = storage.getData(obolibraryURL); + if (data !== null) { + return JSON.parse(data); + } else { + const response = await axios.get(`${baseURL}/search`, {params}); + const data = response.data; + storage.setData(obolibraryURL, JSON.stringify(data)); + return data; + } + } catch (error) { Notifications.showError('Error: Ontology Search Request failed'); } },