Skip to content

Instantly share code, notes, and snippets.

@temmyraharjo
Created August 9, 2018 03:36
Embed
What would you like to do?
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