tweaks to the map data cache, in preperation for detail level specific expiry times
This commit is contained in:
@ -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
|
// 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
|
// 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
|
// however, this is not guaranteed by the standards, but all our supported browsers work this way
|
||||||
|
|
||||||
delete this._cache[qk];
|
delete this._cache[qk];
|
||||||
|
|
||||||
if (date === undefined) date = new Date();
|
var time = new Date().getTime();
|
||||||
this._cache[qk] = { time: date.getTime(), data: data };
|
|
||||||
|
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) {
|
window.DataCache.prototype.get = function(qk) {
|
||||||
@ -50,8 +54,8 @@ window.DataCache.prototype.getTime = function(qk) {
|
|||||||
window.DataCache.prototype.isFresh = function(qk) {
|
window.DataCache.prototype.isFresh = function(qk) {
|
||||||
if (qk in this._cache) {
|
if (qk in this._cache) {
|
||||||
var d = new Date();
|
var d = new Date();
|
||||||
var t = d.getTime() - this.REQUEST_CACHE_FRESH_AGE*1000;
|
var t = d.getTime();
|
||||||
if (this._cache[qk].time >= t) return true;
|
if (this._cache[qk].expire >= t) return true;
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user