A simple Bluesky bot to make sense of the noise, with responses powered by Gemini, similar to Grok.
at main 831 B view raw
1interface CacheEntry<T> { 2 value: T; 3 expiry: number; 4} 5 6class TimedCache<T> { 7 private cache = new Map<string, CacheEntry<T>>(); 8 private ttl: number; // Time to live in milliseconds 9 10 constructor(ttl: number) { 11 this.ttl = ttl; 12 } 13 14 get(key: string): T | undefined { 15 const entry = this.cache.get(key); 16 if (!entry) { 17 return undefined; 18 } 19 20 if (Date.now() > entry.expiry) { 21 this.cache.delete(key); // Entry expired 22 return undefined; 23 } 24 25 return entry.value; 26 } 27 28 set(key: string, value: T): void { 29 const expiry = Date.now() + this.ttl; 30 this.cache.set(key, { value, expiry }); 31 } 32 33 delete(key: string): void { 34 this.cache.delete(key); 35 } 36 37 clear(): void { 38 this.cache.clear(); 39 } 40} 41 42export const postCache = new TimedCache<any>(2 * 60 * 1000); // 2 minutes cache