Created
August 20, 2018 12:43
-
-
Save marcoberri/367c12a04b796876613731cb7871ab47 to your computer and use it in GitHub Desktop.
Cache data on session storage by url with key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* 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