dla
Version:
node.js data loader with caching and support of lists
49 lines • 1.71 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const cache_1 = require("./cache");
class MemoryCache extends cache_1.Cache {
constructor() {
super(...arguments);
this.store = {};
}
has(key) {
return __awaiter(this, void 0, void 0, function* () {
return key in this.store;
});
}
get(key) {
return __awaiter(this, void 0, void 0, function* () {
return this.store[key];
});
}
set(key, value, options) {
return __awaiter(this, void 0, void 0, function* () {
this.store[key] = value;
});
}
setnx(key, value, options) {
return __awaiter(this, void 0, void 0, function* () {
if (!(key in this.store)) {
this.store[key] = value;
}
});
}
remove(key) {
return __awaiter(this, void 0, void 0, function* () {
delete this.store[key];
});
}
flush() {
this.store = {};
}
}
exports.MemoryCache = MemoryCache;
//# sourceMappingURL=memory-cache.js.map
;