From 2a11204ee698b756b6688a11e8999def9643ec23 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Mon, 2 Feb 2015 09:49:25 -0800 Subject: [PATCH] [Persistence] Don't clone in cache Don't clone objects in the persistence cache; instead, ensure that one instance per object is used/given wherever possible. Goal is to keep object state in sync between visible instances for WTD-791 et al. --- .../cache/src/CachingPersistenceDecorator.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/platform/persistence/cache/src/CachingPersistenceDecorator.js b/platform/persistence/cache/src/CachingPersistenceDecorator.js index 9ca964637e..3f2705c428 100644 --- a/platform/persistence/cache/src/CachingPersistenceDecorator.js +++ b/platform/persistence/cache/src/CachingPersistenceDecorator.js @@ -21,16 +21,10 @@ define( var spaces = CACHE_SPACES || [], // List of spaces to cache cache = {}; // Where objects will be stored - // Utility function; avoid sharing one instance everywhere. - function clone(value) { - // Only clone truthy values (no need to clone undefined, false...) - return value && JSON.parse(JSON.stringify(value)); - } - // Place value in the cache for space, if there is one. function addToCache(space, key, value) { if (cache[space]) { - cache[space][key] = { value: clone(value) }; + cache[space][key] = { value: value }; } } @@ -110,7 +104,7 @@ define( */ readObject: function (space, key) { return (cache[space] && cache[space][key]) ? - fastPromise(clone(cache[space][key].value)) : + fastPromise(cache[space][key].value) : persistenceService.readObject(space, key) .then(putCache(space, key)); },