Skip to content

Commit

Permalink
[DUOS-2853][risk=no] Cache doid responses in local storage (#2432)
Browse files Browse the repository at this point in the history
  • Loading branch information
rushtong authored Jan 11, 2024
1 parent c2a0bb8 commit 57ddc0d
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/libs/ontologyService.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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');
}
},
Expand Down

0 comments on commit 57ddc0d

Please sign in to comment.