Is there anything related to a WooCommerce product (that is managed stock) on the homepage?
It seems this is also happening on category pages but product pages appear OK.
I have defined this in template to counteract it for time being:
define( 'DONOTCACHEPAGE', false );
define( 'DONOTCACHEOBJECT', false );
define( 'DONOTCACHEDB', false );
The code that sets those constants will be added to any page that has a WooCommerce product that has a managed stock. So if you display a product on your main page those constants should be added.
OK, I think I understand. As you change the stock of the item with add to cart then you are making sure any managed stock page isn’t cached. That’s gonna totally nuke performance of our site as no way the server can handle so much traffic without a cache and we manage stock levels for all products.
So on pages that I am forcing to cache I will need to update the template to read stock via an ajax request or use something like fragment caching on the stock.
Am I understanding this correctly?
Anytime a product’s status or inventory quantity is checked it is going to set the nocache headers. There probably should be a way to configure when to do that but it’s not setup that way currently.
Yes, it would be very helpful if you could wrap the definitions in an option check so it was possible to disable it without forking or manually specifying in template.
I am assuming that woocommerces normal behaviour is that when an order goes through it invalidates the page cache of all items on the order so stock shows correctly updated.
As you are modifying stock on add to cart wouldn’t it be a better approach to set the stock and then specifically invalidate the cache on that page?
That would allow page caching to work and would be a massive performance increase.
Is there an action I can use that fires after your code has modified the stock that has the product in scope I could use to invalidate the cache of that specific product?
Regarding caching, I believe WooCommerce by default only says to not cache the account, cart, and checkout pages. It will allow product pages to be cached.
I’ll put it on the todo list to allow more granular control over the caching, but I do not know when I will have available free time to work on it. I’m always open to code contributions.
OK, do you have a git repo or just the SVN?
I added a WordPress filter ‘wc_csr_set_nocache’ that you can use to return false if you don’t want the nocache constants to be set.