imc
Version:
IMC is an In-Memory Cache key-value store.
41 lines (40 loc) • 1.22 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
exports.__esModule = true;
var Cache = (function () {
function Cache(store) {
if (store === void 0) { store = {}; }
this.store = store;
}
Cache.prototype.set = function (key, value) {
if (typeof key === 'string') {
this.store[key] = value;
}
else if (key instanceof Object && Object.keys(key).length) {
this.store = __assign(__assign({}, key), this.store);
}
};
Cache.prototype.get = function (key) {
return key ? this.store[key] : this.store;
};
Cache.prototype["delete"] = function (key) {
delete this.store[key];
};
Cache.prototype.clear = function () {
this.store = {};
};
return Cache;
}());
exports.Cache = Cache;
exports.cache = new Cache();
exports["default"] = exports.cache;