diff options
author | mistic100 <mistic@piwigo.org> | 2014-05-24 14:18:04 +0000 |
---|---|---|
committer | mistic100 <mistic@piwigo.org> | 2014-05-24 14:18:04 +0000 |
commit | fea2a4efd1ad085def7cf84cc444325d0815b62e (patch) | |
tree | 892dcb971d34efd7cbff6c31375448a09dfbe73b /admin/themes/default/js | |
parent | 59f418f7986594895a2352e8895250069cff336a (diff) |
feature 3077 : improve cache invalidation
- add "lastmodified" automatic field for categories, groups, users, tags and images tables
- provide a "server key" to the client cache manager
git-svn-id: http://piwigo.org/svn/trunk@28532 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r-- | admin/themes/default/js/LocalStorageCache.js | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/admin/themes/default/js/LocalStorageCache.js b/admin/themes/default/js/LocalStorageCache.js index 49a4fa98d..c18171efc 100644 --- a/admin/themes/default/js/LocalStorageCache.js +++ b/admin/themes/default/js/LocalStorageCache.js @@ -1,7 +1,8 @@ -var LocalStorageCache = function(key, lifetime, loader) { - this.key = key; - this.lifetime = lifetime*1000; - this.loader = loader; +var LocalStorageCache = function(options) { + this.key = options.key + '-' + options.serverId; + this.serverKey = options.serverKey; + this.lifetime = options.lifetime ? options.lifetime*1000 : 3600*1000; + this.loader = options.loader; this.storage = window.localStorage; this.ready = !!this.storage; @@ -14,28 +15,23 @@ LocalStorageCache.prototype.get = function(callback) { if (this.ready && this.storage[this.key] != undefined) { var cache = JSON.parse(this.storage[this.key]); - if (now - cache.timestamp <= this.lifetime) { + if (now - cache.timestamp <= this.lifetime && cache.key == this.serverKey) { callback(cache.data); return; } } this.loader(function(data) { - if (that.ready) { - that.storage[that.key] = JSON.stringify({ - timestamp: now, - data: data - }); - } - + that.set.call(that, data); callback(data); }); }; LocalStorageCache.prototype.set = function(data) { if (this.ready) { - that.storage[that.key] = JSON.stringify({ + this.storage[this.key] = JSON.stringify({ timestamp: new Date().getTime(), + key: this.serverKey, data: data }); } |