How to not cache a page with absence of Cache-Control header using Origin Cache Control

Context
We have a large site with multiple teams and multiple routes that might be cachable or uncacheable. Using individual page rules to handle the caching for these has gotten out of hand because not all teams have access to add rules and also we are using too many rules. As a result, we want to shift the responsibility to cache a page to the origin’s instead of fully using page rules.

Constraints
These are non-default cached resources (e.g. html) so we have to use a CF page rule to set this up as well as having a cookie cache key for the response. Additionally we also cannot browser cache because of needing the cookie cache key. We also want to adopt this incrementally so that existing implementations don’t break if they don’t send a cache-control.

Current solution
We’ve gotten 90% of the way there by enabling a wildcard rule for our pages with the following configuration:

Page Rule:
url: example.com/path/*
Cache Level: Cache Everything (to opt in html)
Custom Cache Key (for cookie cache key)
Origin Cache Control: true

Global Configuration:
Browser Cache TTL: Respect Existing Headers

Test cases
Our server responds with

pass Cache-Control: s-maxage=60,public will return with cf-cache-status: HIT/MISS/EXPIRED
pass Cache-Control: no-store will return with cf-cache-status: BYPASS
problematic No Cache-Control is sent, will return cf-cache-status: Hit

I want this case of no Cache-Control to BYPASS or be DYNAMIC, because we can’t guarantee those resources are cacheable since the origins haven’t added headers to it.

Fixes I’ve tried
I believe the root of the issue is “Cloudflare does cache the resource even if there is no Cache-Control header based on status codes” https://developers.cloudflare.com/cache/about/default-cache-behavior/. When then goes on to say “By default, Cloudflare caches certain HTTP response codes with the following Edge Cache TTL when a cache-control directive or expires response header are not present.” https://developers.cloudflare.com/cache/how-to/configure-cache-status-code/#edge-ttl

I’ve tried to mess with setting no-store on the status code TTL within the page rule, but that seems to just BYPASS everything, since what I really need is setting that turns this status code caching off and then falls to page rules sequentially.

TL;DR
At the end of the day, I basically only want to cache using a wild card page rule that fully respects the origin cache-control header and if it’s not present ignore caching, but that seems out of reach which seems like a pretty basic use case. Any suggestions?

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.