Automattic / batcache

A memcached HTML page cache for WordPress.

Home Page:http://wordpress.org/extend/plugins/batcache/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exclude pages with DONOTCACHEPAGE

kb6673 opened this issue · comments

commented

W3 Total Cache implements a DONOTCACHEPAGE constant and doesn't cache pages where this constant is set. WooCommerce and other plugins have adopted this principle.

I can't do a pull request as my fork differs too much, however here's a snippet of how I implemented DONOTCACHEPAGE in Batcache

if ( defined( 'DONOTCACHEPAGE' ) ) { if ( $batcache->debug_header ) { header("X-batcache: Caching cancelled - DONOTCACHEPAGE defined"); } return; }

Also uses @xyu's debug_header options

I'd love to see this implemented as well. Currently is there any easy way to set certain pages not to cache?

I also think the default should be not to cache any wp-admin urls

Currently is there any easy way to set certain pages not to cache?

We use code like this:

if ( $_SERVER['HTTP_HOST'] == 'SomeSiteWeDontWantToCache.com' ) {
    $batcache['max_age'] = 0;
}

You could check for anything, including path or the existence of a specific cookie (which we also do).

I also think the default should be not to cache any wp-admin urls

Logged in users aren't served cached pages:

https://github.com/Automattic/batcache/blob/master/advanced-cache.php#L333-L341

My method is a bit simpler. I'm using it on a few sites to allow the DONOTCACHEPAGE constant to abort caching. Just submitted a PR. Adding this would really help with plugin compatibility. More plugin developers seem to be using it to address issues discovered with W3TC and WP Super Cache.

This feature is a duplicate ( even tri-plicate? ) of functionality we already have. I'd add the batcache_cancel() function to the list as well.

@vnsavage and @Viper007Bond

I think you may be missing the point here. Yes, Batcache already supports ways to abort the cache, but these "features" you're referring to requires additional configuration on a per site basis.

The idea here was to just let Batcache natively support a popular constant to trigger the cancelation. Both W3TC and WP SuperCache check for DONOTCACHEPAGE, so many plugins like WooCommerce for example will simply look for that constant and abort the cache when needed.

If Batcache just supported it out of the box, there would be less per site configuration when setting up plugins that are already doing some caching conflict resolution out of the box based on DONOTCACHEPAGE

Please reconsider. Thanks!

Is there anyway we can exclude asset files like .js from Batcache?

I cant find a way to make the below snippet work.

https://github.com/Automattic/vip-quickstart/blob/master/www/config/batcache-config.php#L58-L82

if ( substr($_SERVER['REQUEST_URI'], -3) == '.js' ) {
$batcache['max_age'] = 0; // disable batcache
}