UNPKG

machinomy

Version:

Micropayments powered by Ethereum

33 lines 833 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class Entry { constructor(ttl, value) { this.validUntil = Date.now() + ttl; this.value = value; } isLive() { return Date.now() <= this.validUntil; } } class MemoryCache { constructor(ttl) { this.ttl = ttl; this.entries = new Map(); } async get(channelId) { const entry = this.entries.get(channelId); if (entry && entry.isLive()) { return entry.value; } else { this.entries.delete(channelId); return; } } async set(channelId, body) { const entry = new Entry(this.ttl, body); this.entries.set(channelId, entry); } } exports.default = MemoryCache; //# sourceMappingURL=MemoryCache.js.map