@nomyx/assistant
Version:
A powerful assistant library and cli for your AI projects. works with Vertex AI (Claude and Gemini)
39 lines (30 loc) • 924 B
text/typescript
// LOCKED: TRUE
// All content in this file is locked and cannot be edited.
import { CacheManager } from "../types/cache";
import { ProviderResponse } from "../types/chat";
interface CacheEntry {
value: ProviderResponse;
expiry: number;
}
export class MemoryCacheManager implements CacheManager {
private cache: Map<string, CacheEntry> = new Map();
async get(key: string): Promise<ProviderResponse | null> {
const entry = this.cache.get(key);
if (!entry) return null;
if (Date.now() > entry.expiry) {
this.cache.delete(key);
return null;
}
return entry.value;
}
async set(key: string, value: ProviderResponse, ttl: number): Promise<void> {
const expiry = Date.now() + ttl * 1000;
this.cache.set(key, { value, expiry });
}
async delete(key: string): Promise<void> {
this.cache.delete(key);
}
async clear(): Promise<void> {
this.cache.clear();
}
}