* Store a value in KV cache * @param key - The cache key * @param value - The value to cache * @param ttl - Time to live in seconds (optional, defaults to 12 hours with jitter) * @param env - Environment with Cloudflare bindings
( key: string, value: any, env: Env, ttl?: number, )
| 87 | * @param env - Environment with Cloudflare bindings |
| 88 | */ |
| 89 | async function setInCache( |
| 90 | key: string, |
| 91 | value: any, |
| 92 | env: Env, |
| 93 | ttl?: number, |
| 94 | ): Promise<void> { |
| 95 | // Use provided TTL or generate one with jitter |
| 96 | const cacheTTL = ttl || getCacheTTL(); |
| 97 | |
| 98 | // Store in KV cache |
| 99 | if (env?.CACHE_KV) { |
| 100 | try { |
| 101 | await env.CACHE_KV.put(key, JSON.stringify(value), { |
| 102 | expirationTtl: cacheTTL, |
| 103 | }); |
| 104 | } catch (error) { |
| 105 | console.warn("Failed to save to Cloudflare KV:", error); |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Get cached file path for a repository file |
no test coverage detected