We have cache rules which cache content when a cookie value is present and to not cache content when a cookie is not present.
In general, it works. When a cookie is not present we get DYNAMIC, when a cookie is present we get HIT.
The problem is that we get HIT on all pages, even on first load. Also, we notice no page speed difference at all. When we test the cache here apart from Dev Tools where we see a HIT, we see that no cache is present: Cloudflare Cache Detector - Check if Cloudflare Cache Is Working.
We tried to figure out the issue, but so far we are clueless. It could be related to the combination of cache rules or the particular cache rule for the cookie. For the cookie value we use “contains” and not “equals”.
What are the steps to reproduce the issue?
Enable cookie-based cache rule
Login with user (Wordpress based)
Empty all global cloudflare cache
Load any page
Any page will get a HIT at first load instead of a MISS
Also, worth note:
When user is logged in, WordPress sets correctly Cache-Control to private and “no cache”
The TTL setting of the cookie based cache rule is set to ignore Cache-Control-Header and to store cache 1 year (which works apparently at least by not showing DYNAMIC)
The Date of the cache is always shows current time
The expiry date of the cache is current time - 1 day (which should be at least somewhere around + 1 year when the global cache has been emptied before)
Sorry to hear that your cache rule is not working as expected.
The problem is that we get HIT on all pages, even on first load.
Wouldn’t this be expected behavior? Your rule says to cache pages for cookie visitors.
Any page will get a HIT at first load instead of a MISS
If someone else with a cookie visited between the time you purged and your visit, you would get a HIT. Please check the Age header of the HIT to see if it’s a somewhat recent copy.
raising a technical ticket requires a business account,
Go ahead and open it as an Account issue, then share the ticket # here, and we can take a look at it.
Wouldn’t this be expected behavior? Your rule says to cache pages for cookie visitors.
The behavior when Cloudflare Cache is empty is on first visit MISS (as the page is not present in Cloudflare Cache) and on second visit HIT (as the page is now cached and present in Cloudflare Cache). Currently it shows on any page HIT which indicates a problem. Also we don’t see any speed gains, which would be normal result of a cached page.
If someone else with a cookie visited between the time you purged and your visit, you would get a HIT. Please check the Age header of the HIT to see if it’s a somewhat recent copy.
We are conducting the tests on staging environment where no normal user is present. Our tests are conducted immediately after the global cache is cleared. So we can reproduce this problem on any page. No user with cookie has visited the page before in that moment.
Hope we can find the rootcause of the behaviour here.