From 42c48cb93b1ca8c8828235d20b49f45dd52c2c12 Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Tue, 8 Nov 2016 11:20:34 -0800 Subject: [PATCH] disable cache --- .../core/src/models/CachingModelDecorator.js | 80 ++++--------------- platform/core/src/services/Instantiate.js | 2 +- src/adapter/services/Instantiate.js | 2 +- 3 files changed, 17 insertions(+), 67 deletions(-) diff --git a/platform/core/src/models/CachingModelDecorator.js b/platform/core/src/models/CachingModelDecorator.js index 96272b4414..c6f1fe7f85 100644 --- a/platform/core/src/models/CachingModelDecorator.js +++ b/platform/core/src/models/CachingModelDecorator.js @@ -38,75 +38,25 @@ define( this.modelService = modelService; } - // Fast-resolving promise - function fastPromise(value) { - return (value || {}).then ? value : { - then: function (callback) { - return fastPromise(callback(value)); - } - }; - } - CachingModelDecorator.prototype.getModels = function (ids) { - var cacheService = this.cacheService, - neededIds = ids.filter(function notCached(id) { - return !cacheService.has(id); - }); + var loadFromCache = ids.filter(function cached(id) { + return this.cacheService.has(id); + }, this), + loadFromService = ids.filter(function notCached(id) { + return !this.cacheService.has(id); + }, this); - // Update the cached instance of a model to a new value. - // We update in-place to ensure there is only ever one instance - // of any given model exposed by the modelService as a whole. - function updateModel(id, model) { - var oldModel = cacheService.get(id); - - // Same object instance is a possibility, so don't copy - if (oldModel === model) { - return model; - } - - // If we'd previously cached an undefined value, or are now - // seeing undefined, replace the item in the cache entirely. - if (oldModel === undefined || model === undefined) { - cacheService.put(id, model); - return model; - } - - // Otherwise, empty out the old model... - Object.keys(oldModel).forEach(function (k) { - delete oldModel[k]; - }); - - // ...and replace it with the contents of the new model. - Object.keys(model).forEach(function (k) { - oldModel[k] = model[k]; - }); - - return oldModel; + if (!loadFromCache.length) { + return this.modelService.getModels(loadFromService); } - // Store the provided models in our cache - function cacheAll(models) { - Object.keys(models).forEach(function (id) { - var model = cacheService.has(id) ? - updateModel(id, models[id]) : models[id]; - cacheService.put(id, model); - }); - } - - // Expose the cache (for promise chaining) - function giveCache() { - return cacheService.all(); - } - - // Look up if we have unknown IDs - if (neededIds.length > 0) { - return this.modelService.getModels(neededIds) - .then(cacheAll) - .then(giveCache); - } - - // Otherwise, just expose the cache directly - return fastPromise(cacheService.all()); + return this.modelService.getModels(loadFromService) + .then(function (modelResults) { + loadFromCache.forEach(function (id) { + modelResults[id] = this.cacheService.get(id); + }, this); + return modelResults; + }.bind(this)); }; return CachingModelDecorator; diff --git a/platform/core/src/services/Instantiate.js b/platform/core/src/services/Instantiate.js index f966235370..ac292edb19 100644 --- a/platform/core/src/services/Instantiate.js +++ b/platform/core/src/services/Instantiate.js @@ -50,7 +50,7 @@ define( return function (model, id) { var capabilities = capabilityService.getCapabilities(model); id = id || identifierService.generate(); - cacheService.put(id, model); + // cacheService.put(id, model); return new DomainObjectImpl(id, model, capabilities); }; } diff --git a/src/adapter/services/Instantiate.js b/src/adapter/services/Instantiate.js index 3b4c190705..eeced813ae 100644 --- a/src/adapter/services/Instantiate.js +++ b/src/adapter/services/Instantiate.js @@ -39,7 +39,7 @@ define( model.id = id; var capabilities = capabilityService.getCapabilities(model); model.id = old_id; - cacheService.put(id, model); + // cacheService.put(id, model); return new DomainObjectImpl(id, model, capabilities); }; }