Skip to content
Snippets Groups Projects
Commit effd6a76 authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

[fix] Cache: change caches options, when settings changed (enable or disable...

[fix] Cache: change caches options, when settings changed (enable or disable cache persitence) - fix #885
parent 721c85f8
No related branches found
No related tags found
No related merge requests found
Pipeline #8322 failed
......@@ -19,7 +19,7 @@ angular.module('cesium.cache.services', ['angular-cache'])
return settings && settings.useLocalStorage && settings.persistCache && $window.localStorage ? 'localStorage' : 'memory';
}
function fillStorageOptions(options) {
function getCacheOptions(options) {
options = options || {};
options.storageMode = getSettingsStorageMode();
options.deleteOnExpire = (options.storageMode === 'localStorage' || options.onExpire) ? 'aggressive' : 'passive';
......@@ -29,24 +29,6 @@ angular.module('cesium.cache.services', ['angular-cache'])
return options;
}
function onSettingsChanged(settings) {
var newStorageMode = getSettingsStorageMode(settings)
var hasChanged = (newStorageMode !== storageMode);
if (hasChanged) {
storageMode = newStorageMode;
console.debug("[cache] Updating caches with {storageMode: {0}}".format(storageMode));
if (storageMode === 'memory') {
clearAllCaches();
}
_.forEach(_.keys(cacheNames), function(cacheName) {
var cache = CacheFactory.get(cacheName);
if (cache) {
cache.setOptions({storageMode: storageMode});
}
});
}
}
function getOrCreateCache(prefix, maxAge, onExpire){
prefix = prefix || '';
maxAge = maxAge || constants.SHORT;
......@@ -72,7 +54,7 @@ angular.module('cesium.cache.services', ['angular-cache'])
if (cache) return cache;
// Not exists yet: create a new cache
var options = fillStorageOptions({
var options = getCacheOptions({
maxAge: maxAge,
onExpire: onExpire || null
});
......@@ -101,6 +83,21 @@ angular.module('cesium.cache.services', ['angular-cache'])
});
}
function onSettingsChanged(settings) {
var newStorageMode = getSettingsStorageMode(settings)
var hasChanged = (newStorageMode !== storageMode);
if (hasChanged) {
storageMode = newStorageMode;
console.debug("[cache] Updating caches with {storageMode: {0}}".format(storageMode));
_.forEach(_.keys(cacheNames), function(cacheName) {
var cache = CacheFactory.get(cacheName);
if (cache) {
cache.setOptions(getCacheOptions(), true);
}
});
}
}
function addListeners() {
listeners = [
// Listen if node changed
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment