Why CF doesn't cache this worker?

Can someone help me figure out why this worker never gets cached: https://oparse.com/api/cache The response correctly sets cache-control max-age=60, stale-while-revalidate=60 (you can see it in the browser inspector) Yet from both logs ad DR flare extension I can see the response is never cached. What am I doing wrong? The worker is:
export default defineEventHandler(async (event) => {
const now = Date.now()
const cacheHeaders = "max-age=60, stale-while-revalidate=60"
setResponseHeader(event, "Cache-Control", cacheHeaders)
return `Timestamp is: ${now}`
})
export default defineEventHandler(async (event) => {
const now = Date.now()
const cacheHeaders = "max-age=60, stale-while-revalidate=60"
setResponseHeader(event, "Cache-Control", cacheHeaders)
return `Timestamp is: ${now}`
})
6 Replies
Walshy
Walshy3w ago
Workers run before cache You cannot cache in front of a Worker and stop it invoking. You can use the cache API however to cache within the Worker
cosbgn
cosbgnOP3w ago
Not even with cacherules?
cosbgn
cosbgnOP3w ago
it would seem like cache rules run before the worker
No description
cosbgn
cosbgnOP3w ago
Setup like this
No description
Walshy
Walshy3w ago
Cache Rules run before but cache is after So you will see like headers get added but cache is still not done until later
cosbgn
cosbgnOP3w ago
Got it, I'll look at the cache apithanks

Did you find this page helpful?