Behavior of Cache Everything + Origin Cache Control + Browser Cache TTL 0

Background (question at the end)

I’d like to cache a non-standard URL e.g. /graphql?something. My origin will determine what response are cacheable and send a cache-control header with max-age and public/private directives when this is the case. When there’s no cache-control header, it is not cacheable data.

I think I need Cache Everything (docs) to tell CF to deem the /graphql* path cacheable.
I think I need Origin Cache Control (docs) to tell CF to deem the /graphql* path cacheable.

If I don’t send a cache-control header, my data is not cacheable.

Here are the two related doc pages:
https://support.cloudflare.com/hc/en-us/articles/200168276-Understanding-Browser-Cache-TTL
https://support.cloudflare.com/hc/en-us/articles/115003206852-Understanding-Origin-Cache-Control
cache levels / cache everything: https://support.cloudflare.com/hc/en-us/articles/202775670

Here’s a page rule actions example form the API:

[
  {
    "id": "browser_cache_ttl",
    "value": 0
  },
  {
    "id": "cache_level",
    "value": "cache_everything"
  },
  {
    "id": "explicit_cache_control",
    "value": "on"
  }
]

By observation:

  • If I just use Origin Cache Control + Cache Everything, I get 4-hour max-age sent to browsers.
  • If I just use Origin Cache Control, I get DYNAMIC cache statuses and cache-control headers from the origin sent to browsers. This seems to be because my URL is not cacheable.
  • If I just use Origin Cache Control + Browser Cache TTL=30 sec, also DYNAMIC cache status, but with overwritten cache-control headers sent to browsers for 30 seconds. This also seems to be because my URL is not cacheable.
  • With all the actions in the JSON above: Origin Cache Control + Cache Everything + Browser Cache TTL=respect existing headers, I get the expected cache statuses and cache-control sent to browsers, however for requests without a cache-control header from my origin, I think they’re being cached at 4 hours :confused:

Problem

When my server does not send a cache-control header, I think http caching heuristic freshness kicks in, or I simply get the default 4-hour (14400 second) Cloudflare default. This seems to come down to the default behavior of Cache Everything and Respect Existing Headers.

If I set browser cache ttl to 30 seconds with origin cache control, I still get 30 second caching when I want zero. I suppose 30 seconds is better than 4 hours, but I can’t proceed with any caching until I can guarantee I’m not caching non-cacheable data. I’d like the default to be zero, which is oddly like the API representation of the rule. :expressionless:

One alternative is a cache tag, but it seems like I should be able to achieve what I want without cache tags. Maybe cache tags is the right way.

Question

Does this behavior of no cache-control header from an origin with Cache Everything on defaulting to 4 hours seem right? Are Cache Tags the only way to do this?

Browser Cache in built help expanded button shows why

What does the Browser Cache TTL do?

The Browser Cache TTL specifies how long cached files will remain in your visitor’s browser cache. This expiration time is what Cloudflare will set unless longer time periods are specified at your web server.

A longer expiration time ensures faster load times for repeat visitors. However, a longer expiration time also means slower update times if those files are modified.

To learn more about Browser Cache TTL see here.

Note: You can also increase the cache expiration by specifying a longer cache time on the origin server, or you can set a different Cache Expiration for a specific path or resource using the Page Rules app. Cloudflare will use whichever value is longer between your origin server cache headers and your Cloudflare setting

Hi, thanks for replying.

I can’t find that exact documentation anywhere, but the Understanding Browser Cache TTL says the same thing. Could you share how you got to that screen? In either case, I see what browser cache control does, but my problem is different.

The case I care about is when the origin sends no cache-control header. Instead of DYNAMIC cache status, it’s cached four hours. If I use browser cache TTL or not, things that I don’t want to be cached are cached. For example, if the content has the word horses, cachable, but if it has the word apples, not cacheable. I can’t get CF to not cache responses with apples that don’t have a cache-control header. Make sense?

It seems like the only way is to try to guarantee that every origin response has the header.

To tell cloudflare not to cache you set no-cache and no-store cache control header option at your origin server

As to docs help info each option in you dashboard has a help link - clicking on it expands a full explanation of the option

Yeah, this morning I added some bits to my server to attempt to always set a cache-control header. This isn’t optimal because sometimes systems fail. I think reaching out to support may also make sense.

Thanks again :+1:

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