Skip to content

Instantly share code, notes, and snippets.

@temmyraharjo
Created August 9, 2018 03:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save temmyraharjo/441bf2a71993e296ec9c590b1cddc532 to your computer and use it in GitHub Desktop.
Save temmyraharjo/441bf2a71993e296ec9c590b1cddc532 to your computer and use it in GitHub Desktop.
function getOrSetCache (key, functionObject) {
var item = sessionStorage.getItem(key);
if (item) {
var objItem = JSON.parse(item);
return objItem;
}
var result = functionObject();
var stringifyResult = JSON.stringify(result);
sessionStorage.setItem(key, stringifyResult);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment