Fetch request to bypass cache (in worker)

I want to be able to use fetch without using the cache and was surprised to see this isn’t readily possible.

The problem is that if I use fetch then it just takes from the cache so I can’t easily make a ‘clean fetch’.

await fetch(new Request('https://example.com/cats.html'))

Why is there no option something like: cf: { bypassCache: true } ?

The only way I can see to achieve this is:

var response = await fetch(new Request('https://example.com/cats.html?cacheBuster=' + Number(new Date())));
caches.default.put(new Request('https://example.com/cats.html'), response)

Is there really no way to force a clean fetch?

You could use the cacheTtl property inside cf to handle cache duration in seconds.

const handleRequest = async (event) => {
	
	const init = {
		cf: {
			cacheTtl: 0
		}
	}

	let response = await fetch('https://example.com/cats.html', init)

	// Cloudflare does not caches html files by default
	// Maybe your origin is sending a Cache-Control header
	response = new Response(response.body, response)
	response.headers.set('Cache-Control', 's-maxage=0')
	return response
}