help getting page cache dialed in
-
Hello–I’m trying to get my page cache set up properly and have a question.
I’m testing a “category archive” in a WooCommerce site, basically just a view of all the products in a particular category. I’ve got my page cache enabled (memcached) and the “Expires Header Lifetime” field in browser cache is set to 86400 seconds (browser cache is disabled for now–once I get page cache set up properly I’ll move to browser cache).
When I test the page and look at the headers, though, I believe the page is not being served from the cache. This is a dedicated VPS on AWS.
I’m seeing “cache-control: max-age=0” in the request headers. Shouldn’t this say 86400 not 0?I’ll paste some screenshots below. The URL I’m testing is https://staging.swansislandcompany.com (authenticate with server using these credentials).
Do I have something misconfigured here? I’ve looked over the documentation and tried different approaches but it seems I must be missing something. Any help would be greatly appreciated! Thank you.
The page I need help with: [log in to see the link]
-
Hello @megunticook
Thank you for reaching out and I am happy to help!
If you are seeing different rules applied then the ones you have selected in the Performance>Browser Cache, there are a couple of things you should consider.In Perfomrance>Install, you can see the rules based on your current configuration. The rules need to match your nginx.conf file un your website dir. If the rules are not there, you should make sure to copy them and paste them to the nginx.conf.
If the rules are present in the nginx.conf it means that there are no permission issues so the problem is not in the rules per se.
In that same nginx.conf file, you should only have the W3TC rules that are setting the BC headers. If you have any other rules custom or set by another plugin, you should make sure to remove those rules to avoid conflict.
If there are no other rules to set the cache control header for example, the reason is that the server configuration is prevening the W3TC rules.
What I mean by this is that either you have some rules set in the upper level of the server folder structure that are setting this (any configuration file in any upper level of the folder structure overrides the config file in the website folder.)Now, if the your server is for example on apache+nginx. there is also a chance that the W3TC recognizes .htaccess and the server is proccessing the files with Nginx, in which case you should make sure to check the server configuration and bypass the apache/nginx rules and let the configuration file in your websit folder to set the rules.
I hope this helps!
Thanks!Thanks @vmarko for your tips. I checked my .htaccess file and it was blank so I copied/pasted the contents from Performance>Install as you recommended. Permissions on .htaccess are 664. Is W3TC not able to write to this file?
Here’s the contents of .htaccess:
# BEGIN W3TC WEBP location ~* ^(?<path>.+)\.(jpe?g|png|gif)$ { if ( $http_accept !~* "webp|\*/\*" ) { break; } add_header Vary Accept; try_files ${path}.webp $uri /index.php?$args; } # END W3TC WEBP
If I understand you correctly there should be cache rules here but they’re missing?
I checked my NGINX config. and there’s no cache rules anywhere that I can see. I was missing this line which I just added:
include /var/www/html/nginx.conf;
But after restarting nginx, saving W3TC settings, and emptying caches, the contents of .htaccess haven’t changed and neither have the rewrite rules shown in Performance>Install.
When I inspect various pages in my browser the only cache header I see is CacheControl: max-age=0.
Any idea what’s going on here? Thank you.,
- This reply was modified 8 months, 3 weeks ago by Megunticook. Reason: misspelled word
Hello @megunticook
Thank you for your feedback.
The W3 Total cache should writhe the rules in the configuration file that it recogizes. In your example, the files are handled by the nginx, however, you also have the .htaccess
The rules are that are in the .htaccess cannot do anyhting if the server configuration does not allow this.
So in this case, you should check with the hosting provider, and see if you can bypass the ngix to allow .htaccess to handle the rewrite.
Any rules that you can find in the Performance>Install should be added in the configuration file in the website folder.I hope this clarifies this.
Thanks!
Thanks @vmarko. This is a VPS that I manage so I have full control over nginx config. Are you saying that in my situation W3TC should be writing rules to my nginx config. file? Or the .htaccess file?
It sounds like there’s a permissions problem. What does W3TC recommend for permissions assigned to the nginx.conf file? Thank you.
Currently my nginx config. file is owned by the “ubuntu” user and group, with permissions set to 664.
I turned on debugging for page cache and got this:
<!-- Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/ Object Caching 3/11681 objects using APC Page Caching using Memcached (Cookie is rejected) Page cache debug info: Engine: Memcached Cache key: Creation Time: 1709584753.000s Header info: Expires: Wed, 11 Jan 1984 05:00:00 GMT Cache-Control: no-cache, must-revalidate, max-age=0, no-store, private Content-Type: text/html; charset=UTF-8 Link: <https://staging.swansislandcompany.com/wp-json/>; rel="https://api.w.org/" Link: <https://staging.swansislandcompany.com/wp-json/wp/v2/product_cat/1847>; rel="alternate"; type="application/json" Database Caching using Memcached (Request-wide modification query) Served from: staging.swansislandcompany.com @ 2024-03-04 15:39:13 by W3 Total Cache -->
- This reply was modified 8 months, 3 weeks ago by Megunticook.
- This reply was modified 8 months, 3 weeks ago by Megunticook. Reason: added a detail
- This reply was modified 8 months, 3 weeks ago by Megunticook.
- This reply was modified 8 months, 3 weeks ago by Megunticook.
Update: I added the path to my nginx config. file in the W3TC general settings, and now I have an nginx.conf file in my root directory with the same contents as I listed above.
Tested a page and the request header has this line:Cache-Control: max-age=0
Nothing in the response header.
I turned on debugging for Page cache, loaded the page (logged out of WordPress) and this is in the source code:
<!-- Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/ Object Caching 47/11605 objects using APC Page Caching using Memcached Page cache debug info: Engine: Memcached Cache key: ace4046df135f9e0cc430ef9adb8834e_ssl Creation Time: 1709655570.000s Header info: Content-Type: text/html; charset=UTF-8 Link: <https://staging.swansislandcompany.com/wp-json/>; rel="https://api.w.org/" Link: <https://staging.swansislandcompany.com/wp-json/wp/v2/product_cat/1847>; rel="alternate"; type="application/json" Database Caching 1/1536 queries in 0.667 seconds using Memcached (Request-wide modification query) Served from: staging.swansislandcompany.com @ 2024-03-05 11:19:30 by W3 Total Cache -->
Hmmm…still seems like the headers are wrong/missing and there’s no page cache happening. What should I be looking at next to fix this?
Thank you.
Hi @vmarko, I’m doing more testing here trying to get the page cache working correctly and now I’m not seeing any cache headers whatsoever. Scratching my head as to why when I have page cache enabled. Any thoughts? Here’s the debug information from my latest test this morning. Why is the “header info” blank? Shouldn’t there be cache headers?
<!-- Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/ Object Caching 44/11619 objects using APC Page Caching using Memcached Page cache debug info: Engine: Memcached Cache key: ace4046df135f9e0cc430ef9adb8834e_ssl Creation Time: 1709825751.000s Header info: Content-Type: text/html; charset=UTF-8 Link: <https://staging.swansislandcompany.com/wp-json/>; rel="https://api.w.org/" Link: <https://staging.swansislandcompany.com/wp-json/wp/v2/product_cat/1847>; rel="alternate"; type="application/json" Database Caching 1/1539 queries in 0.772 seconds using Memcached (Request-wide modification query) Served from: staging.swansislandcompany.com @ 2024-03-07 10:35:51 by W3 Total Cache -->
Hello @megunticook
As you can see from the debug:
`</p> <pre class=”wp-block-code”><code>Page cache debug info: Engine: Memcached Cache key: ace4046df135f9e0cc430ef9adb8834e_ssl Creation Time: 1709825751.000s</code></pre> <p class=””>`
The page is cached. You are reffertg to Browser Cache or more precise cache-control header which is different from Page Caching.
I cannot see the header either, and it might be because the website is not public.Thanks!
Thanks for clarifying that @vmarko. So the server is serving up the page from where it’s stored in memcached–great! I misread the debug info. Making some progress here. And thanks for clarifying about the cache headers, I was obviously confused about that.
This page is an “archive” showing all the products in a WooCommerce product category. Let’s say I add a new product to the category. Will W3TC automatically purge the cache or do I need to do that manually?Hello @megunticook
You are most welcome.
You can go to Performance>Page Cache>Purge policy, there you can set when the cache should be purged and on which pages.Thanks!
Thank you @vmarko, got it. I have “posts page” and “post page” checked. Would that include Woo Commerce products and category archives or do I need to add some URLs to the “Additional Pages” section of the Purge Policy?
And what about WordPress pages (as opposed to posts)–do those need to be added to the “additional page” section as well?
Appreciate your help. Got an “A” in my GTMetrix test of https://swansislandcompany.com/product-category/sale/ so I think I’m making some progress here! Your assistance is invaluable.
Hello @megunticook
Thank you for your feedback.
That should be sufficient. What I would recommend is to test this and see if the cache is purged for those pages when a new product is added.This all depends on how those posts/pages are created.
Please test this and let me know if it works with the default settings.Thanks!
Back to report results of my testing @vmarko:
I pulled up a Woo Commerce product category page in Firefox and used Dev Tools to disable the browser cache and observe behavior. I was not logged into WordPress/WooCommerce in the browser I used to test.
Using a different browser that was logged in as an admin., I cycled between “published” and “draft” status for a product belonging to the category while refreshing the category page in Firefox after each change. Here’s what I found:
- Switching a published product to “draft” doesn’t purge the category page from the page cache.
- Neither does clicking “Performance>Purge Current Page” on the admin. toolbar while viewing the category page but “Performance>Purge Modules>Page Cache does clear the category page from the page cache
- Clicking on “Empty All Caches” in the WordPress admin. also purges the category page
- Adding the URL of the category page to the “Purge Policy” of the W3TC “Page Cache” settings purges the category page from the page cache when changing the “published” status of ANY product, even one that’s not in that category.
So it appears that to ensure a category page is purged from the W3TC page cache after removing/adding/altering a product belonging to that category, I would need to either:
- manually purge each relevant category page using “Performance>Purge Modules>Page Cache”
- click “empty all caches” which would empty everything across the board, not just the category page I want to target
- add the URLs of all category pages to the page cache purge policy, which would mean that all category pages are purged whenever any product is changed
Does all that sound correct to you? Am I missing some way to configure W3TC to automatically purge any relevant category pages when a product is changed but not all of them?
Thank you.
- The topic ‘help getting page cache dialed in’ is closed to new replies.