• Resolved Winston

    (@anarchoi)


    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:

    1. 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.
    2. 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
    3. 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.
    4. 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.

    • This topic was modified 1 year, 2 months ago by Winston.
    • This topic was modified 1 year, 2 months ago by Winston.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @anarchoi

    I am sorry about the issue you are experiencing and I am happy to help!

    First I need to mention that W3 Total Cache and WP Super Cache are two optimization plugins and in no circumstances is recommended to use more than one caching solution. So I would strongly advise removing WP Super Cache plugin and only using W3 Total Cache for the optimization to avoid the issues you mentioned.
    The reason for the issues you are having is the multiple layers of the caching. In this case, you have cached the pages with W3 Total Cache, WP Super Cache, and Cloudflare.
    By default, W3 Total Cache does not cache pages with query strings, so if that random query string is cached, it may be cached by the other plugin.

    The problem with the Browser Cache rules is the fact that the Cloudflare browser Cache TTL is not configured to respect the origin headers. Also, if the wp super cache is setting headers you may encounter the issues. You need to configure Cloudflare Browser Cache TTL to respect the origin header and make sure that you do not have any custom headers set in any configuration file in the upper level of the server folder structure.
    Check more details below on CF headers

    https://developers.cloudflare.com/cache/concepts/default-cache-behavior/

    Can you please clarify what “WP Super Cache plugin (W3TC support built-in)” means?
    I would recommend the following:

    • Remove the WP Super Cache plugin completely (Once again it’s not recommended to use more than one caching plugin)
    • Manually delete the wp-content/cache/ folder
    • Configure the Cloudflare to respect the origin headers
    • In W3 Total Cache settings enable “Don’t cache pages for logged in users” and disable “Don’t cache pages for following user roles”
    • Make sure to save all settings and purge the cache and also purge the Cloudflare cache.

      It would be great if you could share the website URL


      Thanks!
    Thread Starter Winston

    (@anarchoi)

    Hi, thanks for the reply

    The problem is not the use of 2 caching plugins, but the fact that W3TC is overwriting the headers. If the caching headers would be correct, then CF would respect them and not cache the page. Let’s try to fix the headers and see how it goes.

    WP Super Cache is designed to support 2 layers of caching. They call the WP page cache “fallback page cache” and if W3TC is not enabled then they recommend to use their own fallback page cache.

    If we have to disable one of the plugins, then it would definitely be W3TC because CF cache has much better improvement on overall loading speed, and when W3TC is disabled the cache works perfectly without any issue. But we would still like to use it as fallback page cache. Just need to fix the headers.

    By default, W3 Total Cache does not cache pages with query strings, so if that random query string is cached, it may be cached by the other plugin.

    WP Super Cache doesn’t cache query string neither, and CF will not cache a max-age=0 if the headers are not overwritten.

    In this case, you have cached the pages with W3 Total Cache, WP Super Cache, and Cloudflare.

    WP Super Cache doesn’t cache anything, it just an integration of CF “cache everything” rule, so we have 2 layers of caching and not 3. The other layers of caching are disabled when the max-age=0 header is not being overwritten by W3TC.

    The problem with the Browser Cache rules is the fact that the Cloudflare browser Cache TTL is not configured to respect the origin headers. You need to configure Cloudflare Browser Cache TTL to respect the origin header

    CF will never cache a page if the browser cache returns a max-age of zero:

    “Resources that match a Cache Everything Page Rule are still not cached if the origin web server sends a Cache-Control header of max-age=0, private, no-cache, or an Expires header with an already expired date.” https://developers.cloudflare.com/cache/concepts/customize-cache/

    We even tried overriding the CF Cache TTL with a page rule, tested both with Origin Cache Control on or off: https://prnt.sc/vjmi04trPpYp

    Also, if the wp super cache is setting headers you may encounter the issues.

    This option is disabled https://prnt.sc/izMNk2nC37cd

    https://developers.cloudflare.com/cache/concepts/default-cache-behavior/

    The page you linked says “Cloudflare does not cache the resource when:
    The Cache-Control header is set to private, no-store, no-cache, or max-age=0″

    The cache-control header on the homepage is set to no-cache max-age=0 when W3TC is disabled. But when W3TC is enabled, this header is overwritten with a max-age=86400

    Can you please clarify what “WP Super Cache plugin (W3TC support built-in)” means?

    It has options built-in to support W3TC, even if they recommend using their own page cache. It is supposed to automatically purge CF cache when W3TC flushs its caches https://prnt.sc/qeeTF4OEHVgY

    • Manually delete the wp-content/cache/ folder
    • Configure the Cloudflare to respect the origin headers
    • In W3 Total Cache settings enable “Don’t cache pages for logged in users” and disable “Don’t cache pages for following user roles”
    • Make sure to save all settings and purge the cache and also purge the Cloudflare cache.

    Already tried all this

    • This reply was modified 1 year, 2 months ago by Winston.
    • This reply was modified 1 year, 2 months ago by Winston.
    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @anarchoi

    Thank you for your feedback.

    I am a bit confused. WP super Cache does not have fallback page cache option. Can you please confirm the you are talking about WP Super Cache or the Super Page Cache for Cloudflare?

    Thanks!

    Thread Starter Winston

    (@anarchoi)

    Sorry for the confusion, I am talking about Super Page Cache for Cloudflare

    To make debugging easier, we have currently disabled Cloudflare caching (site paused in CF) and WP Super Page Cache for CF. So the only cache is W3TC right now.

    If I disable W3TC completely, then the homepage correctly shows the max-age=3600 (generated by the header.php code I posted earlier)

    Now if I delete everything in /wp-content/cache/ then ONLY the first hit to the homepage will show the max-age=3600 header

    Any subsequent hit on the homepage, and the header is now completely gone. As soon as W3TC generates the page cache and saves the index.html in /wp-content/cache/ then the max-age=3600 header is gone

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @anarchoi

    Thank you for your feedback and thanks for the clarification.

    Can you please also confirm that the Cache Control header and Expires header are disabled in Performance>Browser Cache?

    Also, is it possible for you to share the website URl?

    Tanks!

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    No activity for a week.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘admin bar is cached and max-age header is overwritten + 3 other problems’ is closed to new replies.