Last active
June 16, 2019 02:17
-
-
Save jeanmachuca/88594aed5997fd6930bc26dc5cd05727 to your computer and use it in GitHub Desktop.
QCObjects ComplexCacheControl Example
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
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