Skip to content

Instantly share code, notes, and snippets.

@marcoberri
Created August 20, 2018 12:43
Show Gist options
  • Save marcoberri/367c12a04b796876613731cb7871ab47 to your computer and use it in GitHub Desktop.
Save marcoberri/367c12a04b796876613731cb7871ab47 to your computer and use it in GitHub Desktop.
Cache data on session storage by url with key
/**
*
* Verifica la presenza di un singolo valore in session storage,
* se non esiste esegue la chiamata
*
* @param {string} url
* @returns {*}
* @memberof ApiService
*/
public getLookUp(url: string): any {
if (sessionStorage.getItem(url)) {
return JSON.parse(sessionStorage.getItem(url));
} else {
this.getUrlDetail(url).then(result => {
sessionStorage.setItem(url, JSON.stringify(result));
return result;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment