automattic / batcache Goto Github PK
View Code? Open in Web Editor NEWA memcached HTML page cache for WordPress.
Home Page: http://wordpress.org/extend/plugins/batcache/
A memcached HTML page cache for WordPress.
Home Page: http://wordpress.org/extend/plugins/batcache/
last year's question has been unanswered at:
https://wordpress.org/support/plugin/batcache/
is that forum live? or you only monitor github?
Composer is a popular php dependancy manger. Many of automattic plugins already support it, such as jetpack and babble. Supporting it is simple, only requires having a composer.json file in the root of the project and for the repo not using git submodules.
It is extremely useful if you want to load plugins from github 👍
Hi!
I have 2 WordPress sites on the same server with Batcache and APC Object Cache Backend plugin installed. Unique WP_APC_KEY_SALT defined on each wordpress site.
All plugins & WordPress core are up-to-date.
Debug option turned on both sites.
No error has been logged in Nginx & php error logs.
When I check the debug message: -
travellersquestion.com ( without WPML ) works perfectly, Batcache message is shown;
tangrufus.com ( with WPML ) shows no trace about Batcache
If WPML is deactivated, Batcache works on tangrufus.com.
Any suggestions to make Batcache works with WPML?
Thanks!
Hi I am using jetpack_is_mobile and batcache doesnt seem to support it and is saving only a single copy.
Hi, in my vip dev environment I got these after activating batcache following the istructions:
Warning: include_once(/srv/wp-content/object-cache.php): failed to open stream: No such file or directory in /srv/wp-content/mu-plugins/batcache/advanced-cache.php on line 355
Warning: include_once(): Failed opening '/srv/wp-content/object-cache.php' for inclusion (include_path='.:/usr/local/php/lib/php') in /srv/wp-content/mu-plugins/batcache/advanced-cache.php on line 355
reading advanched-cache.php seems like the absence of object-cache.php triggers a return at the half of the file...
why don't check if file exists before including, to avoid warning?
and why object cache is required for a large portion of the script, but it's not included in the plugin itself?
where can i find and download a stable version of it?
batcache_post() should look for an empty object before it tries to check its properties.
I followed you instructions and I don't get stats in the head. I don't know if anything actually works ...
I am on shared hosting and I can active apcu extension in cpanel. I tried with php5.6 and php 7.0 .
Note : I have access to server with ssh, I can use php cli but no root. I use wordpress under bedrock from roots
under php 5.6 I get
$ php -v
ea-php-cli Copyright 2016 cPanel, Inc.
PHP 5.6.27 (cli) (built: Oct 16 2016 12:40:50)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
$ php -i | grep memcache
memcache
memcache support => enabled
memcache.allow_failover => 1 => 1
memcache.chunk_size => 8192 => 8192
memcache.default_port => 11211 => 11211
memcache.default_timeout_ms => 1000 => 1000
memcache.hash_function => crc32 => crc32
memcache.hash_strategy => standard => standard
memcache.max_failover_attempts => 20 => 20
memcached
memcached support => enabled
libmemcached version => 1.0.18
memcached.compression_factor => 1.3 => 1.3
memcached.compression_threshold => 2000 => 2000
memcached.compression_type => fastlz => fastlz
memcached.serializer => php => php
memcached.sess_binary => 0 => 0
memcached.sess_connect_timeout => 1000 => 1000
memcached.sess_consistent_hash => 0 => 0
memcached.sess_lock_expire => 0 => 0
memcached.sess_lock_max_wait => 0 => 0
memcached.sess_lock_wait => 150000 => 150000
memcached.sess_locking => 1 => 1
memcached.sess_number_of_replicas => 0 => 0
memcached.sess_prefix => memc.sess.key. => memc.sess.key.
memcached.sess_randomize_replica_read => 0 => 0
memcached.sess_remove_failed => 0 => 0
memcached.sess_sasl_password => no value => no value
memcached.sess_sasl_username => no value => no value
memcached.store_retry_count => 2 => 2
memcached.use_sasl => 0 => 0
Registered save handlers => files user memcache memcached
How can I be sure that batcache plugin works ?
thanks
Currently there is no way to clear all urls stored in batcache. The batcache manager only seems to clear post page on update. However if there is a site wide change, such as changing theme, installing plugin or editting the customizer, all urls should be flushed.
I think there is a way we could do this, without keeping track of all urls in cache. We could do something similar to advanced-post-cache. In the bit code, when you send a flush, it changes the group. This effectively changes the salts the cache key and forces caches to regenerate.
I was going to start work on this, but I thought it would be better to get people' thoughts first.
I think an example on how to use a custom configuration would be really helpful for people who don't like reading the code to know how to do that.
I'm doing this by having a file named batcache-config.php
, which is included in wp-config.php
this way:
if ( file_exists( dirname( __FILE__ ) . '/batcache-config.php' ) ) {
include( dirname( __FILE__ ) . '/batcache-config.php' );
}
And this is the content of my batcache-config.php
:
<?php
// =================
// Batcache settings
// =================
global $batcache;
$batcache = array(
'max_age' => 300,
'remote' => 0,
'times' => 1,
'seconds' => 0,
'group' => 'batcache',
'unique' => array(),
'headers' => array(),
'cache_redirects' => false,
'redirect_status' => false,
'redirect_location' => false,
'uncached_headers' => array( 'transfer-encoding' ),
'debug' => true,
'cache_control' => true,
'cancel' => false,
);
Maybe someone could come up with a cleaner way to do this.
I think this is a great plugin, and I hope this helps.
<b>Warning</b>: Trying to access array offset on value of type bool in <b>/home/subdomains/staging/wp-content/advanced-cache.php</b> on line <b>472</b><br />
i see this warning
We’re seeing a lot of the following notices in debug.log:
[02-Apr-2015 21:33:01 UTC] PHP Notice: Undefined index: HTTP_HOST in advanced-cache.php on line 388
[02-Apr-2015 21:33:01 UTC] PHP Notice: Undefined index: REQUEST_METHOD in advanced-cache.php on line 389
[02-Apr-2015 21:33:01 UTC] PHP Notice: Undefined property: batcache::$query in advanced-cache.php on line 391
The “Undefined property” notice is related to #36, but the other two we don’t see mentioned in any issues or PRs.
We wanted to touch base before submitting a pull request since these notices might be related to our setup, which is also running behind Varnish. Thanks!
Notice: Undefined property: batcache::$query in /base/data/home/apps/s~continuous-wordpress-cms/test-permalink-1.377309360575349926/wordpress/wp-content/advanced-cache.php on line 388
Warning: call_user_func_array() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in /base/data/home/apps/s~continuous-wordpress-cms/test-permalink-1.377309360575349926/wordpress/wp-includes/plugin.php on line 192
It seems that a simple if statement to assign the property should solve the issue.
By default, PUT requests aren't exempted from Batcache. This causes... issues with WP-API/JSON, especially when using Basic auth, as there's no cookie to override and cause a bypass. Suggest we bypass for PUT, PURGE, and DELETE requests.
Insert at advanced-cache.php
line 229:
// Never batcache on PUT request.
if ('PUT' === $_SERVER['REQUEST_METHOD'] || 'PURGE' === $_SERVER['REQUEST_METHOD'] || 'DELETE' === $_SERVER['REQUEST_METHOD']) {
return;
}
I'll put an actual PR in for this too.
Props to @allan23 for working this up.
First off - fantastic plugin. Thanks for making this available!
Secondly, it seems like batcache employs only very simple cache clearing functionality out of the box. What would you recommend in order to implement more granular cache flushing like one might find in W3TC? Would you recommend just creating our own simple admin UI to flush the full cache or individual pages, or is there a tool already in place to do these types of things? Thanks!
there are common cookies that will disable batcache because there is bad default cookie configuration. Currently, all cookies that begin with wp will cause cache to bypass. But there are no wp cookies I am aware of that should disable cache. But there are cookies like wp_lang or wpl_* from wpeka gdpr plugin, that will cause batcache to not cache the page. I run into this issue in Pressable hosting sertvice, where they are using batcache for their distributed Edge Cache implementation, but there is no way to change configuration of it
I made pull request with my proposed changes in default behavior
I'm getting this warning for call_user_func_array()
in plugins.php
when batcache is installed:
PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback, first
array member is not a valid class name or object in wordpress/wp-includes/plugin.php
on line 173
I patched my batcache.php
as described in #21.
Anyone know if this is a bug or a problem in my configuration?
Could somoene from the team update the wordpress.org version so it could match the Github one?
Mainly so it doesn't delete any WP SUPER CACHE files which has the same name in the same place. I know you wouldn't use both but for testing purposes would be good to be able to switch between the 2.
https://github.com/Automattic/batcache/blob/master/advanced-cache.php#L429
What's up with that?
can you add the following to the Batcache class?
var $do;
var $genlock;
I have verbose error_reporting running on eMusic and we get a ton of lines of Batcache notices in the logs - would be sweet as pie if we could get those out of there.
Thanks,
Scott Taylor
There does not seem to be absolutely any instructions whatsoever across the entire internet that outline how to uninstall / delete Batcache.
I figured it would be obvious:
Did all of this, and the files on my client's WordPress installation are still caching and it is absolutely impossible to develop with this on.
If anyone could please advise as to a way to disable this ridiculously pervasive plugin, I would greatly appreciate it.
Thanks!
create_function
should be replaced with an anonymous function for PHP 7.2 support. create_function
is deprecated in PHP 7.2
Hi,
I'm trying to get around this problem for one my client but unable to find any solution. Here is server header:
curl -I https://saibabaguide.com
HTTP/1.1 200 OK
Server: nginx
Date: Sun, 10 Jun 2012 21:06:02 GMT
Content-Type: text/html
Connection: keep-alive
X-Whom: l2-com-saiba
Vary: Cookie
Last-Modified: Sun, 10 Jun 2012 20:58:34 +0000
Cache-Control: max-age=152, must-revalidate
Front-End-Https: on
The "Last-Modified: Sun, 10 Jun 2012 20:58:34 +0000" should be "Last-Modified: Sun, 10 Jun 2012 20:58:34 GMT". Is there any setting to change this? In my php.ini, i got the following line:
date.timezone=America/Chicago
How do I change +0000 to GMT.
Thanks!
!
Some plugins, like the ActivityPub plugin, allow getting a JSON object representing your post when querying a post URL with an application/json
header.
This proves problematic when using Batcache, since those requests end up being cached (a potentially good thing), but served back to regular site visitors.
Here is an instance of this happening:
https://fedi.jeremy.hu/@jeremy/statuses/01GVFG2QMBJTFH4VBJT2VZQ8NZ
It would be nice if such requests were at least not cached, or maybe cached separately so they could be served back later on.
The only place that the _version
key gets set is in the batcache manager plugin. It uses get_permalink()
to determine the URL. This is a problem if /wp-admin/
is accessed through a different domain than the main site. For us it sets the key using cms.site.com
, but batcache looks it up using site.com
, so it misses every time. I am not sure how to best fix this, but we have a nasty str_replace
hacked in for now.
When a post is deleted, clean_post_cache
is fired after the post is deleted, this causes the Batcache function batcache_post
to throw a Notice (as the post doesn't exist) and also fails to clean the cache URL (as the permalink can not be retrieved). My proposed solution would be to hook batcache_post
into delete_post
so it can be run before the post is deleted.
The "generated in" comment appears in the main site page source but it doesn't appear in the page source for sub sites.
Does this mean Batcache is working on the main site only?
Where in batcache, do I define the memcached server? Ours is not on localhost. I looked all through the file advanced-cache.php
and didn't see it defined anywhere.
I need to find a way to break the cache for a user systematically within either a javascript or php function. We are trying to provide an ad lite experience for subscribed users. The problem is when after they login to Piano (not wordpress), the cached page, with the ads, remains, at least until the cache naturally breaks. This has been extremely frustrating. This seems to be especially a problem on mobile devices.
Any help to figure this out would be very appreciated.
It has been identified that Batcache only caches Apache headers. This becomes problematic when the server is nginx.
Hi, I'm just wondering why you have this line:
$batcache->configure_groups();
after this line:
$batcache->url_version = (int) wp_cache_get("{$batcache->url_key}_version", $batcache->group);
What if the cache key depends on 'batcache' existing in the set of global groups. Wouldn't it make more sense to switch the two lines?
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
So currently I have a PR #61 to add some improvements to cache clearing in batcache manger. But as I want to use batcache to cache for a much longer time than 5 minutes, I wanted to be sure that caches are clearing. To that end I wrote this https://github.com/spacedmonkey/batcache-manager . It builds on work of @skeltoac but clears out a lot more different kind of urls. I am still working on this, but I was wondering if people were interested in project. Should it be part of batcache? Is there anything else it could clear at the same time?
Related #62
Say I have 180 seconds as the default expiry on Memcached.
Bob creates a blog post at 12:00:00 AM. This increments Batcache's internal cache key that represents the most up-to-date version in the database. Let's call this url_key. The url_key version gets bumped to 1
. url_key will expire in 180 seconds in Memcached, at 12:03:00 AM.
Lisa visits Bob's site at 12:00:30 AM. Batcache doesn't have a copy of this page, so it caches the page. Batcache's internal cache key that represents the version that the cached version of the page is at (let's call this the page cache key) gets set to whatever the url_key is at, so it gets set to 1
. The page cache key gets set to expire at 12:04:00 (the default 180 seconds plus an extra 30 seconds that Batcache specifies).
At 12:02:00 AM, Bob realizes he made a spelling error, and updates his post. The url_key version gets bumped to 2
, but since the cache key already exists in Memcached, the expiration will still happen at 12:03:00.
No one visits Bob's site until Joey does at 12:03:05. The url_key's expiration time has come, so it gets reset to 0
. However, the page cache key is still at 1, as it doesn't expire until 12:04:00, so Batcache will not recache the page until that time comes, so Bob's copy fix won't be seen until then.
If you update a post, the cache for it's pages is not cleared. IE: example.com/my-post/2/ will not clear.
Notice: Undefined property: batcache::$genlock in /base/data/home/apps/s~continuous-wordpress-cms/test-permalink-1.377309360575349926/wordpress/wp-content/advanced-cache.php on line 510
Sometimes it appears reading the posts.
I think that the solution should be simply a declaration of the property at the beginning of the class setting it to "false" or with an empty value.
I tried to use cheeztest (https://github.com/Automattic/cheeztest/) with batcache and look like cheeztest requires a function called vary_cache_on_function() in order to function correctly. Can you open source it?
readme says Stable Tag: 1.4
https://plugins.svn.wordpress.org/batcache/tags/1.4/readme.txt
readme in github says Stable Tag: 1.2
file says Version 1.2
in 1.4 branch
https://plugins.svn.wordpress.org/batcache/tags/1.4/batcache.php
i haven't diff'd files with what's on wp repo but i'd hope this repo would be currrent
While you're at it fix the url too (rem extend/ slug) ;)
Plugin URI: http://wordpress.org/extend/plugins/batcache/
var $times = 2; // Only batcache a page after it is accessed this many times... (two or more)
var $seconds = 0; // ...in this many seconds (zero to ignore this and use batcache immediately)
Hi, after I set $seconds = 0; I alwasy get the following comments:
generated in 0.243 seconds
64311 bytes batcached for 7200 seconds
And Never see the ‘served from batcache’ comment. Is it right? Thanks.
generated 10 seconds ago
generated in 0.124 seconds
served from batcache in 0.001 seconds
expires in 7190 seconds
The optional plugin have on the svn, wp repo the version number 1.2.
is the development on github actual or it is different? The master branch is currently newer from the commit updates, but what is the status of the wp repo?
Thanks for feedback.
This would probably require a massive refactoring of batcache, but it would be very cool if it could serve stale content in the case that the site is experiencing problems. (e.g. database connection problems)
I believe this would require either adding a grace period to the cache expiration, or doing away with cache expiration entirely. And then storing the real expiration timestamp alongside the cached response. When generating any fresh response you could (hopefully) look for any error status codes, and if there is an error try to use a previously cached version of that page.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.