diff --git a/code/map_data_cache.js b/code/map_data_cache.js index d6868557..a03e33de 100644 --- a/code/map_data_cache.js +++ b/code/map_data_cache.js @@ -26,15 +26,19 @@ window.DataCache = function() { } -window.DataCache.prototype.store = function(qk,data,date) { +window.DataCache.prototype.store = function(qk,data,freshTime) { // fixme? common behaviour for objects is that properties are kept in the order they're added // this is handy, as it allows easy retrieval of the oldest entries for expiring // however, this is not guaranteed by the standards, but all our supported browsers work this way delete this._cache[qk]; - if (date === undefined) date = new Date(); - this._cache[qk] = { time: date.getTime(), data: data }; + var time = new Date().getTime(); + + if (freshTime===undefined) freshTime = this.REQUEST_CACHE_FRESH_AGE*1000; + var expire = time + freshTime; + + this._cache[qk] = { time: time, expire: expire data: data }; } window.DataCache.prototype.get = function(qk) { @@ -50,8 +54,8 @@ window.DataCache.prototype.getTime = function(qk) { window.DataCache.prototype.isFresh = function(qk) { if (qk in this._cache) { var d = new Date(); - var t = d.getTime() - this.REQUEST_CACHE_FRESH_AGE*1000; - if (this._cache[qk].time >= t) return true; + var t = d.getTime(); + if (this._cache[qk].expire >= t) return true; else return false; }