File size: 757 Bytes
c7052c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Minimal in-memory cache for provider credential caching (Azure Entra, AWS STS, etc.)
const cache = new Map<string, { value: any; expiresAt: number }>();

class SimpleCache {
  async get<T>(key: string, _options?: any): Promise<T | null> {
    const entry = cache.get(key);
    if (!entry) return null;
    if (Date.now() > entry.expiresAt) {
      cache.delete(key);
      return null;
    }
    return entry.value as T;
  }

  async set(key: string, value: any, options?: { ttl?: number }): Promise<void> {
    const ttl = options?.ttl ?? 300; // default 5 minutes
    cache.set(key, { value, expiresAt: Date.now() + ttl * 1000 });
  }
}

const instance = new SimpleCache();

export function requestCache(_env?: any): SimpleCache {
  return instance;
}