Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. var dataObject = {id:1,
  2. prop1:1,
  3. prop2:2
  4. };
  5.  
  6. var cache = new ComplexStorageCache({
  7. index: dataObject.id,
  8. load: (cacheController) => {
  9. dataObject = {
  10. id:dataObject.id,
  11. prop1:dataObject.prop1*2, // changing a property value
  12. prop2:dataObject.prop2
  13. };
  14. return dataObject;
  15. },
  16. alternate: (cacheController) => {
  17. dataObject = cacheController.cache.getCached(dataObject.id); // setting dataObject with the cached value
  18. return;
  19. }
  20. });
  21.  
  22. // Next time you can get the object from the cache
  23. var dataObjectCopyFromCache = cache.getCached(dataObject.id);
  24. console.log(dataObjectCopyFromCache); // will show the very same object value than dataObject
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement