UNPKG

airship-server

Version:

Airship is a framework for Node.JS & TypeScript that helps you to write big, scalable and maintainable API servers.

82 lines 2.81 kB
"use strict"; 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 BaseCache_1 = require("../domain/BaseCache"); class MemoryCache extends BaseCache_1.BaseCache { constructor() { super(); this._storage = new Map(); this._ttls = new Map(); } cache(key, value, ttl) { return __awaiter(this, void 0, void 0, function* () { this._storage.set(key, value); if (!ttl) return; this._ttls.set(key, { started: Date.now(), ttl }); setTimeout(() => { this._ttls.delete(key); this._storage.delete(key); }, ttl); }); } get(key) { return __awaiter(this, void 0, void 0, function* () { return this._storage.get(key); }); } getTTL(key) { return __awaiter(this, void 0, void 0, function* () { let ttlInfo = this._ttls.get(key); if (!ttlInfo) return -1; let delta = Date.now() - ttlInfo.started; if (delta > ttlInfo.ttl) return 0; else return ttlInfo.ttl - delta; }); } del(key) { return __awaiter(this, void 0, void 0, function* () { throw new Error('not implemented'); }); } setnx(key, value) { return __awaiter(this, void 0, void 0, function* () { throw new Error('not implemented'); }); } getset(key, value) { return __awaiter(this, void 0, void 0, function* () { throw new Error('not implemented'); }); } expire(key, ttl) { return __awaiter(this, void 0, void 0, function* () { throw new Error('not implemented'); }); } keys(key) { return __awaiter(this, void 0, void 0, function* () { throw new Error('not implemented'); }); } exists(key) { return __awaiter(this, void 0, void 0, function* () { throw new Error('not implemented'); }); } } exports.default = MemoryCache; //# sourceMappingURL=MemoryCache.js.map