MrLabubu =)))
MrLabubu =)))
CDCloudflare Developers
Created by MrLabubu =))) on 3/2/2024 in #workers-help
Cloudflare worker Cache not work
Hi, I tried to put the cache but not work, not sure why. here is my code app.get('/get_all_order_status', async (ctx) => { const cacheUrl = ctx.req.url; const cacheKey = new Request(cacheUrl.toString(), ctx.req); const cache = caches.default;
let fromCache = true; let response = await cache.match(cacheKey); if (!response) { const data = await Model.getAllOrderStatus(); response = new Response(JSON.stringify(data), { headers: { 'content-type': 'application/json' }, }); // Add a custom header to the response before putting it in the cache fromCache = false; // Cache the response indefinitely try { console.log(cacheKey.method, cacheKey.url); console.log(response.status, response.statusText); response.headers.append("Cache-Control", "s-maxage=10000000"); ctx.executionCtx.waitUntil(cache.put(cacheKey, response.clone())); } catch (error) { console.error('Error putting data in cache:', error); } } response.headers.set('X-From-Cache', fromCache.toString()); return response; }); The cacheKey and response is OK but cache.put not work.
6 replies
CDCloudflare Developers
Created by MrLabubu =))) on 2/21/2024 in #workers-help
Issue connect Worker and Planetscale
No description
3 replies