From f991dcfb7643bbf1f96fbddecd334cc033f49098 Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Tue, 8 Nov 2016 13:50:13 -0800 Subject: [PATCH] Clear cache when no transactions active --- platform/commonUI/edit/bundle.js | 3 ++- .../edit/src/services/TransactionService.js | 18 +++++++++++++++--- platform/core/src/models/ModelCacheService.js | 4 ++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/platform/commonUI/edit/bundle.js b/platform/commonUI/edit/bundle.js index d2e9a684ae..a5b5fb463f 100644 --- a/platform/commonUI/edit/bundle.js +++ b/platform/commonUI/edit/bundle.js @@ -347,7 +347,8 @@ define([ "implementation": TransactionService, "depends": [ "$q", - "$log" + "$log", + "cacheService" ] }, { diff --git a/platform/commonUI/edit/src/services/TransactionService.js b/platform/commonUI/edit/src/services/TransactionService.js index 3c234ca882..7324982925 100644 --- a/platform/commonUI/edit/src/services/TransactionService.js +++ b/platform/commonUI/edit/src/services/TransactionService.js @@ -34,9 +34,10 @@ define( * @param $q * @constructor */ - function TransactionService($q, $log) { + function TransactionService($q, $log, cacheService) { this.$q = $q; this.$log = $log; + this.cacheService = cacheService; this.transactions = []; } @@ -87,14 +88,25 @@ define( /** * All persist calls deferred since the beginning of the transaction - * will be committed. + * will be committed. If this is the last transaction, clears the + * cache. * * @returns {Promise} resolved when all persist operations have * completed. Will reject if any commit operations fail */ TransactionService.prototype.commit = function () { var transaction = this.transactions.pop(); - return transaction ? transaction.commit() : Promise.reject(); + if (!transaction) { + return Promise.reject(); + } + if (!this.isActive()) { + return transaction.commit() + .then(function (r) { + this.cacheService.flush(); + return r; + }.bind(this)) + } + return transaction.commit(); }; /** diff --git a/platform/core/src/models/ModelCacheService.js b/platform/core/src/models/ModelCacheService.js index 783509a774..0e3daf2121 100644 --- a/platform/core/src/models/ModelCacheService.js +++ b/platform/core/src/models/ModelCacheService.js @@ -77,5 +77,9 @@ define([], function () { return this.cache; }; + ModelCacheService.prototype.flush = function () { + this.cache = {}; + }; + return ModelCacheService; });