25 lines
592 B
JavaScript
25 lines
592 B
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.MemoryCache = void 0;
|
|
class MemoryCache {
|
|
store = new Map();
|
|
get(key) {
|
|
const hit = this.store.get(key);
|
|
if (!hit) {
|
|
return undefined;
|
|
}
|
|
if (Date.now() >= hit.expiresAt) {
|
|
this.store.delete(key);
|
|
return undefined;
|
|
}
|
|
return hit.value;
|
|
}
|
|
set(key, value, ttlMs) {
|
|
this.store.set(key, {
|
|
value,
|
|
expiresAt: Date.now() + ttlMs
|
|
});
|
|
}
|
|
}
|
|
exports.MemoryCache = MemoryCache;
|