diff --git a/web/src/app/js/base.js b/web/src/app/js/base.js index e3f844c..c200fb1 100644 --- a/web/src/app/js/base.js +++ b/web/src/app/js/base.js @@ -177,6 +177,33 @@ function _get_func_params(func) { } const http = { + cache: { + _key: function(name) { return 'httpcache__'+name }, + get: function(name) { + const key = http.cache._key(name); + try { return JSON.parse(localStorage[key]) } + catch (e) { } + return localStorage[key]; + }, + set: function(name, value) { + const key = http.cache._key(name); + localStorage[key] = value; + localStorage[key+'_ts'] = new Date().getTime(); + }, + del: function(name) { http.cache.expire(name) }, + expire: function(name) { + const key = http.cache._key(name); + delete localStorage[key]; + delete localStorage[key+'_ts']; + }, + expired: function(name, secs) { + const key = http.cache._key(name); + const ts = new Date().getTime(); + const ts2 = parseInt(localStorage[key+'_ts']); + if (isNaN(ts2)) return true; + return ((ts - ts2) / 1000) > secs; + }, + }, request: function(method, path, payload, callbk) { payload = payload || null; callbk = callbk || null;