mirror of
https://github.com/nasa/openmct.git
synced 2025-01-03 03:46:42 +00:00
Clear cache when no transactions active
This commit is contained in:
parent
42c48cb93b
commit
f991dcfb76
@ -347,7 +347,8 @@ define([
|
|||||||
"implementation": TransactionService,
|
"implementation": TransactionService,
|
||||||
"depends": [
|
"depends": [
|
||||||
"$q",
|
"$q",
|
||||||
"$log"
|
"$log",
|
||||||
|
"cacheService"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -34,9 +34,10 @@ define(
|
|||||||
* @param $q
|
* @param $q
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function TransactionService($q, $log) {
|
function TransactionService($q, $log, cacheService) {
|
||||||
this.$q = $q;
|
this.$q = $q;
|
||||||
this.$log = $log;
|
this.$log = $log;
|
||||||
|
this.cacheService = cacheService;
|
||||||
this.transactions = [];
|
this.transactions = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,14 +88,25 @@ define(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* All persist calls deferred since the beginning of the transaction
|
* 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
|
* @returns {Promise} resolved when all persist operations have
|
||||||
* completed. Will reject if any commit operations fail
|
* completed. Will reject if any commit operations fail
|
||||||
*/
|
*/
|
||||||
TransactionService.prototype.commit = function () {
|
TransactionService.prototype.commit = function () {
|
||||||
var transaction = this.transactions.pop();
|
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;
|
return this.cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ModelCacheService.prototype.flush = function () {
|
||||||
|
this.cache = {};
|
||||||
|
};
|
||||||
|
|
||||||
return ModelCacheService;
|
return ModelCacheService;
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user