chore: overhaul infrastructure and integrate @mintel packages
Some checks failed
🧪 CI (QA) / 🧪 Quality Assurance (push) Failing after 1m3s
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
This commit is contained in:
43
apps/web/src/utils/cache/memory-adapter.ts
vendored
Normal file
43
apps/web/src/utils/cache/memory-adapter.ts
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user