From 600fe1f91c48302a376a99e4eb57baf22687c386 Mon Sep 17 00:00:00 2001 From: Jon Atkins Date: Sat, 21 Feb 2015 23:32:57 +0000 Subject: [PATCH] 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... --- code/data_cache.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/data_cache.js b/code/data_cache.js index c9dda218..f7c2c443 100644 --- a/code/data_cache.js +++ b/code/data_cache.js @@ -31,11 +31,11 @@ window.DataCache.prototype.store = function(qk,data,freshTime) { if (freshTime===undefined) freshTime = this.REQUEST_CACHE_FRESH_AGE*1000; 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) { - 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; }