* Get a value from KV cache * @param key - The cache key * @param env - Environment with Cloudflare bindings * @returns The cached value or null if not found
(key: string, env: Env)
| 65 | * @returns The cached value or null if not found |
| 66 | */ |
| 67 | async function getFromCache(key: string, env: Env): Promise<any> { |
| 68 | // Check KV store for cached value |
| 69 | if (env?.CACHE_KV) { |
| 70 | try { |
| 71 | const result = await env.CACHE_KV.get(key, { type: "json" }); |
| 72 | console.log(`Cache retrieval for key ${key}:`, result); |
| 73 | return result; |
| 74 | } catch (error) { |
| 75 | console.warn("Failed to retrieve from Cloudflare KV:", error); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | return null; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Store a value in KV cache |
no test coverage detected