kibana-123
Version:
Kibana is an open source (Apache Licensed), browser based analytics and search dashboard for Elasticsearch. Kibana is a snap to setup and start using. Kibana strives to be easy to get started with, while also being flexible and powerful, just like Elastic
36 lines (28 loc) • 718 B
JavaScript
import _ from 'lodash';
import angular from 'angular';
export default function LocalCacheFactory() {
function LocalCache(opts) {
opts = opts || {};
let _id = opts.id || function (o) { return '' + o; };
let _cache = {};
this.get = function (obj) {
let id = _id(obj);
return _cache[id] ? JSON.parse(_cache[id]) : null;
};
this.set = function (obj, val) {
let id = _id(obj);
let clean = !_cache.hasOwnProperty(id);
_cache[id] = angular.toJson(val);
return clean;
};
this.clear = function (obj) {
if (!obj) {
_cache = {};
return;
}
let id = _id(obj);
delete _cache[id];
};
}
return LocalCache;
};