caches not found for next on pages

I'm following the cache guide to implement caching with NextJS, however I'm getting caches is not defined inside my route handler. What's the correct way to access the cache API in Next? And is this expected to work locally?
// Cloudflare caching
const cache = caches.default
const cacheRequest = generateCloudflareCacheRequest({
request,
function_handle,
prompt_updated_at: functionData.prompt_updated_at,
})
let cacheResponse = null
try {
cacheResponse = await cache.match(cacheRequest)
} catch (e) {
logError('[serious] Error fetching CF cache', { e, cacheRequest })
}
// Cloudflare caching
const cache = caches.default
const cacheRequest = generateCloudflareCacheRequest({
request,
function_handle,
prompt_updated_at: functionData.prompt_updated_at,
})
let cacheResponse = null
try {
cacheResponse = await cache.match(cacheRequest)
} catch (e) {
logError('[serious] Error fetching CF cache', { e, cacheRequest })
}
3 Replies
James
James5mo ago
is this in next dev specifically?
kyle
kyleOP5mo ago
Yes, just now I tested it in a preview build and it worked! @Better James do you happen to know the default TTL of caching this way? Is it 1 hour on Pro? https://developers.cloudflare.com/cache/how-to/edge-browser-cache-ttl/
Cloudflare Docs
Edge and Browser Cache TTL · Cloudflare Cache (CDN) docs
Edge Cache TTL (Time to Live) specifies the maximum time to cache a resource in the Cloudflare global network. Edge Cache TTL is not visible in …
James
James5mo ago
Not sure
Want results from more Discord servers?
Add your server