mirror of
https://github.com/nasa/openmct.git
synced 2024-12-21 22:17:49 +00:00
Clear cache when no transactions active
This commit is contained in:
parent
42c48cb93b
commit
f991dcfb76
@ -347,7 +347,8 @@ define([
|
||||
"implementation": TransactionService,
|
||||
"depends": [
|
||||
"$q",
|
||||
"$log"
|
||||
"$log",
|
||||
"cacheService"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -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();
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -77,5 +77,9 @@ define([], function () {
|
||||
return this.cache;
|
||||
};
|
||||
|
||||
ModelCacheService.prototype.flush = function () {
|
||||
this.cache = {};
|
||||
};
|
||||
|
||||
return ModelCacheService;
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user