Some checks failed
🧪 CI (QA) / 🧪 Quality Assurance (push) Failing after 1m3s
- Restructure to pnpm monorepo (site moved to apps/web) - Integrate @mintel/tsconfig, @mintel/eslint-config, @mintel/husky-config - Implement Docker service architecture (Varnish, Directus, Gatekeeper) - Setup environment-aware Gitea Actions deployment
43 lines
975 B
TypeScript
43 lines
975 B
TypeScript
/**
|
|
* Memory Cache Adapter
|
|
* Simple in-memory implementation
|
|
*/
|
|
|
|
import type { CacheAdapter, CacheConfig } from './interfaces';
|
|
|
|
export class MemoryCacheAdapter implements CacheAdapter {
|
|
private cache = new Map<string, { value: any; expiry: number }>();
|
|
private defaultTTL: number;
|
|
|
|
constructor(config: CacheConfig = {}) {
|
|
this.defaultTTL = config.defaultTTL || 3600;
|
|
}
|
|
|
|
async get<T>(key: string): Promise<T | null> {
|
|
const item = this.cache.get(key);
|
|
if (!item) return null;
|
|
|
|
if (Date.now() > item.expiry) {
|
|
this.cache.delete(key);
|
|
return null;
|
|
}
|
|
|
|
return item.value as T;
|
|
}
|
|
|
|
async set<T>(key: string, value: T, ttl?: number): Promise<void> {
|
|
const finalTTL = ttl || this.defaultTTL;
|
|
this.cache.set(key, {
|
|
value,
|
|
expiry: Date.now() + (finalTTL * 1000)
|
|
});
|
|
}
|
|
|
|
async del(key: string): Promise<void> {
|
|
this.cache.delete(key);
|
|
}
|
|
|
|
async clear(): Promise<void> {
|
|
this.cache.clear();
|
|
}
|
|
} |