Skip to content

Instantly share code, notes, and snippets.

@jeanmachuca
Last active June 16, 2019 02:17
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 jeanmachuca/88594aed5997fd6930bc26dc5cd05727 to your computer and use it in GitHub Desktop.
Save jeanmachuca/88594aed5997fd6930bc26dc5cd05727 to your computer and use it in GitHub Desktop.
QCObjects ComplexCacheControl Example
var dataObject = {id:1,
prop1:1,
prop2:2
};
var cache = new ComplexStorageCache({
index: dataObject.id,
load: (cacheController) => {
dataObject = {
id:dataObject.id,
prop1:dataObject.prop1*2, // changing a property value
prop2:dataObject.prop2
};
return dataObject;
},
alternate: (cacheController) => {
dataObject = cacheController.cache.getCached(dataObject.id); // setting dataObject with the cached value
return;
}
});
// Next time you can get the object from the cache
var dataObjectCopyFromCache = cache.getCached(dataObject.id);
console.log(dataObjectCopyFromCache); // will show the very same object value than dataObject
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment