diff --git a/www/js/services/cache-services.js b/www/js/services/cache-services.js index 9650fdb23c1c4473aba2560f09add3d4f5b2079f..64cfe86e721df078a76c0ead095f8759e7b88617 100644 --- a/www/js/services/cache-services.js +++ b/www/js/services/cache-services.js @@ -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