Files
mb-grid-solutions.com/lib/services/cache/memory-cache-service.ts
Marc Mintel 20cafce97d
Some checks failed
Build & Deploy / 🔍 Prepare Environment (push) Successful in 8s
Build & Deploy / 🏗️ Build (push) Failing after 12s
Build & Deploy / 🧪 QA (push) Successful in 1m13s
Build & Deploy / 🚀 Deploy (push) Has been skipped
Build & Deploy / 🔔 Notifications (push) Successful in 2s
fix(ci): fix eslint compatibility, downgrade to v8, and fix lint errors
2026-02-05 11:15:41 +01:00

27 lines
724 B
TypeScript

import type { CacheService } from "./cache-service";
export class MemoryCacheService implements CacheService {
private cache = new Map<string, { value: unknown; expiry: number | null }>();
async get<T>(key: string): Promise<T | null> {
const item = this.cache.get(key);
if (!item) return null;
if (item.expiry && item.expiry < Date.now()) {
this.cache.delete(key);
return null;
}
return item.value as T;
}
async set<T>(key: string, value: T, ttlSeconds?: number): Promise<void> {
const expiry = ttlSeconds ? Date.now() + ttlSeconds * 1000 : null;
this.cache.set(key, { value, expiry });
}
async delete(key: string): Promise<void> {
this.cache.delete(key);
}
}