Changeset 28532 for trunk/admin/themes/default/js/LocalStorageCache.js
- Timestamp:
- May 24, 2014, 4:18:04 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/themes/default/js/LocalStorageCache.js
r28494 r28532 1 var LocalStorageCache = function(key, lifetime, loader) { 2 this.key = key; 3 this.lifetime = lifetime*1000; 4 this.loader = loader; 1 var LocalStorageCache = function(options) { 2 this.key = options.key + '-' + options.serverId; 3 this.serverKey = options.serverKey; 4 this.lifetime = options.lifetime ? options.lifetime*1000 : 3600*1000; 5 this.loader = options.loader; 5 6 6 7 this.storage = window.localStorage; … … 15 16 var cache = JSON.parse(this.storage[this.key]); 16 17 17 if (now - cache.timestamp <= this.lifetime ) {18 if (now - cache.timestamp <= this.lifetime && cache.key == this.serverKey) { 18 19 callback(cache.data); 19 20 return; … … 22 23 23 24 this.loader(function(data) { 24 if (that.ready) { 25 that.storage[that.key] = JSON.stringify({ 26 timestamp: now, 27 data: data 28 }); 29 } 30 25 that.set.call(that, data); 31 26 callback(data); 32 27 }); … … 35 30 LocalStorageCache.prototype.set = function(data) { 36 31 if (this.ready) { 37 th at.storage[that.key] = JSON.stringify({32 this.storage[this.key] = JSON.stringify({ 38 33 timestamp: new Date().getTime(), 34 key: this.serverKey, 39 35 data: data 40 36 });
Note: See TracChangeset
for help on using the changeset viewer.