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'); } },