Does cacheTtl work in the playground?


#1

I was testing a request like this in the playground:

addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

/**
 * Fetch and log a request
 * @param {Request} request
 */
async function handleRequest(request) {
  console.log('Got request', request)
  const response = await fetch("https://mywebsite.com", { cf: { cacheTtl: 3000 } })
  console.log('Got response', response)
  return response
}

However when looking at server logs for my website, I saw that the server was still being hit on subsequent requests.

Does cacheTtl work in the playground?

Is there documentation that shows what doesn’t work in the playground?

Thanks!


#2

Hi! As you’ve guessed, the cache is not active in the playground. The only way to test caching is to deploy your Worker through your Cloudflare account.

You’re absolutely right we should document the differences between the playground and the real-world better, we will work on it.