experimental: JSON encode the data stored in the cache

in theory, keeping the javascript objects directly in the cache is a good thing. any instances of, for example, portals on the map, will share the data objects with those in the cache, limiting the overheads for cached items in use
however, in practice
- relatively large and complex data structures for cached data. and as some items expired from the cache may have data in live portals, etc, complex for garbage collection to clean up. strings, on the other hand - one single object to clean, zero references from anything else
- the cache is used as an alternative to network requests. therefore the extra time to encode/parse the strings is no real issue
- lower memory overheads? it's liekly a single string is more efficient on RAM use, even taking into account that some objects will be both encoded in the string, and duplicated in live entities on the map

time will tell if this is better or worse than direct object storage...
This commit is contained in:
Jon Atkins 2015-02-21 23:32:57 +00:00
parent f5b565b284
commit 600fe1f91c

View File

@ -31,11 +31,11 @@ window.DataCache.prototype.store = function(qk,data,freshTime) {
if (freshTime===undefined) freshTime = this.REQUEST_CACHE_FRESH_AGE*1000; if (freshTime===undefined) freshTime = this.REQUEST_CACHE_FRESH_AGE*1000;
var expire = time + freshTime; var expire = time + freshTime;
this._cache[qk] = { time: time, expire: expire, data: data }; this._cache[qk] = { time: time, expire: expire, data: JSON.stringify(data) };
} }
window.DataCache.prototype.get = function(qk) { window.DataCache.prototype.get = function(qk) {
if (qk in this._cache) return this._cache[qk].data; if (qk in this._cache) return JSON.parse(this._cache[qk].data);
else return undefined; else return undefined;
} }