Ignore:
Timestamp:
May 24, 2014, 4:18:04 PM (10 years ago)
Author:
mistic100
Message:

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
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;
     1var 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;
    56 
    67  this.storage = window.localStorage;
     
    1516    var cache = JSON.parse(this.storage[this.key]);
    1617   
    17     if (now - cache.timestamp <= this.lifetime) {
     18    if (now - cache.timestamp <= this.lifetime && cache.key == this.serverKey) {
    1819      callback(cache.data);
    1920      return;
     
    2223 
    2324  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);
    3126    callback(data);
    3227  });
     
    3530LocalStorageCache.prototype.set = function(data) {
    3631  if (this.ready) {
    37     that.storage[that.key] = JSON.stringify({
     32    this.storage[this.key] = JSON.stringify({
    3833      timestamp: new Date().getTime(),
     34      key: this.serverKey,
    3935      data: data
    4036    });
Note: See TracChangeset for help on using the changeset viewer.