48 lines
1.1 KiB
JavaScript

import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
var Cache = function () {
function Cache() {
_classCallCheck(this, Cache);
this._root = null;
this._store = new Map();
}
Cache.prototype.empty = function empty() {
return this._store.size === 0;
};
Cache.prototype.has = function has(key) {
return this._store.has(key);
};
Cache.prototype.get = function get(key, defaultValue) {
var res = this.has(key) ? this._store.get(key) : this.root();
return typeof res === 'undefined' || res === null ? defaultValue : res;
};
Cache.prototype.add = function add(key, value) {
if (this.empty()) {
this._root = key;
}
this._store.set(key, value);
};
Cache.prototype.update = function update(key, value) {
if (this.has(key)) {
this._store.set(key, value);
}
};
Cache.prototype.remove = function remove(key) {
this._store.delete(key);
};
Cache.prototype.root = function root() {
return this._store.get(this._root);
};
return Cache;
}();
export default Cache;