admin bar is cached and max-age header is overwritten + 3 other problems
-
We use this plugin along with CF cache everything rule and WP Super Cache plugin (W3TC support built-in)
Current config: page caching (disk enhanced) + “Don’t cache for logged in users” is checked and also for all other roles. CF is connected to WP with api key.
Temporarily disabled: Object caching, DB caching, minify, Redis.4 problems:
- The admin bar is always cached. Can reproduce this issue easily by logging as admin, adding a random variable to the url (www.example.com/index.php?v=5434543) then opening the same URL in a private navigation window (no cookies) and the admin bar is displayed for logged-out users.
- Pages are cached by CF when logged as admin – Cf-Cache-Status header is always HIT. When W3TC is disabled, Cf-Cache-Status is BYPASS or DYNAMIC
- The cache is not purged when a new article is published. If W3TC is disabled it works. Both W3TC and CF Super Cache plugins are configured to purge cache when posts are created.
- The max-age and cache-control headers are overwritten. We tried disabling browser caching and removing everything in the .htaccess, then in the theme’s header.php we overwrite the headers:
if ( is_admin() ) { header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0", true); header("Pragma: no-cache", false); header("Expires: on, 01 Jan 1970 00:00:00 GMT", false); } else { if ( is_home() ) { $ts = gmdate("D, d M Y H:i:s", time() + (60*60)) . " GMT"; header("Expires: $ts", true); header("Pragma: cache", false); header("Cache-Control: max-age=3600", false); } else { $ts = gmdate("D, d M Y H:i:s", time() + (60*60*24)) . " GMT"; header("Expires: $ts", true); header("Pragma: cache", false); header("Cache-Control: max-age=".(60*60*24), false); } }
But it doesn’t work. Here is the headers on the homepage:
Alt-Svc: h3=":443"; ma=86400 Cache-Control: public, max-age=86400 Cf-Cache-Status: HIT
The headers are the same when logged as admin.
The max-age issue seems intermittent, sometimes I can see max-age=3600 for a few hours BUT the page cache is not really purged after 1h. For testing we added this in header.php:
<meta name="cache_date" content="<?= date("Y-m-d H:i", time()) ?>" >
and this morning for a few hours I was seeing a max-age=3600 with a meta cache_date older than 12 hours ago (even if multiple new posts were published in last hours)
All of the 4 problems happen only when W3TC is enabled, the other CF Super Cache work fine.
When W3TC is disabled:
homepage as admin is never cached:
Cache-Control: max-age=0, no-cache Cf-Cache-Status: DYNAMIC
homepage when logged out is always cached for the correct duration:
Cache-Control: public, max-age=3600 Cf-Cache-Status: HIT
When W3TC is disabled, the admin bar is never cached (because headers are not overwritten, so the no-cache is respected by CF) and also the CF cache is always purged when new posts are added.
- The topic ‘admin bar is cached and max-age header is overwritten + 3 other problems’ is closed to new replies.