Cloudflare (Workers) Fetch Cache & Redirects Behavior
In Cloudflare (Workers), how does the 'fetch' caching behavoir work when the fetched resource is a redirected to somewhere else?
Let's say we have a cache everything and TTL on a specific fetch request, that fetch requests ends up doing a temporary redirect to another URL, will it, the URL that is being redirected to, be fetched from cloudflare's cache if available?
A concrete example for our Storyblok scenario: If we don't have a cache version (cv) available and we fetch
/v2/cdn/stories/home?key=234234234
, Storyblok will redirect this to a link that does have the cache value (cv) query param /v2/cdn/stories/home?cv=2342342234&key=234234234
, will the second URL be fetched from the cloudflare cache or not? Preferably in this case, if we get a redirect status code from Storyblok, we don't want to cache that response. But if it redirects to an URL that does have the cache version (cv) included, and we already have that cached, we want to actually retrieve it from the cloudflare cache if available there.
Might I need to add a response status code specific cache rule? Or how does the caching behavoir work when redirects are involved?1 Reply
Or would it be smart to do this using redirect: "manual", and then refetch myself if redirect is detected with cv query param with the proper cache TTLs and properties? This way I can also potentially sort the query params if needed to ensure better cache hits? 🤔