UNPKG

tspace-mysql

Version:

Tspace MySQL is a promise-based ORM for Node.js, designed with modern TypeScript and providing type safety for schema databases.

62 lines 1.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MemoryCache = void 0; class MemoryCache { cache; constructor() { this.cache = new Map(); } provider() { return 'memory'; } async all() { return new Promise((resolve) => { const values = []; for (const value of this.cache.values()) { values.push(value); } return resolve(values); }); } exists(key) { return new Promise((resolve) => { const cached = this.cache.get(key); return resolve(cached != null); }); } async get(key) { return await new Promise((resolve) => { const cached = this.cache.get(key); if (!cached) { return resolve(null); } if (Date.now() > cached.expiredAt) { this.cache.delete(key); return resolve(null); } return resolve(cached.value); }); } set(key, value, ms) { return new Promise((resolve) => { const expiredAt = Date.now() + ms; this.cache.set(key, { value, expiredAt }); return resolve(); }); } clear() { return new Promise((resolve) => { this.cache.clear(); return resolve(); }); } delete(key) { return new Promise((resolve) => { this.cache.delete(key); return resolve(); }); } } exports.MemoryCache = MemoryCache; exports.default = MemoryCache; //# sourceMappingURL=MemoryCache.js.map