Problem
TTLCache uses in-memory storage (cache.ts line 18). In distributed/serverless deployments, each instance has separate cache causing inconsistent data.
Recommended Solution
Use Redis for distributed caching:
import { Redis } from '@upstash/redis';
const redis = new Redis({
url: process.env.REDIS_URL
});
export class DistributedTTLCache<T> {
async get(key: string): Promise<T | null> {
const data = await redis.get(key);
return data as T | null;
}
async set(key: string, value: T, ttlSeconds: number): Promise<void> {
await redis.setex(key, ttlSeconds, JSON.stringify(value));
}
}
Program Template
Suggested Labels
architecture, caching, redis, distributed, gssoc-eligible
EOF
)
Problem
TTLCache uses in-memory storage (cache.ts line 18). In distributed/serverless deployments, each instance has separate cache causing inconsistent data.
Recommended Solution
Use Redis for distributed caching:
Program Template
Suggested Labels
architecture, caching, redis, distributed, gssoc-eligible
EOF
)