Currently a lot of useful caching plugins are available for wordpress. Most popular and successful among them are W3 Total Cache and Super Cache and Batcache. All of these plugins help improve speed of website and reduce page load time. This post is to make you aware of the features and problems of caching plugins.
How caching plugins works -
- A request comes for a page with several request parameters including URL, cookies, referer, form input
- WordPress generates a response page after parsing all the request parameters
- Main page specific content depends upon URL but other things on the page may depend upon different request parameter
- Caching plugin stores this response when the request to the URL comes
- Another requests come for same page and caching plugin intercepts it before wordpress start generation of response
- Caching plugin then checks if it has the response for URL in cache and sends that cached copy directly
Notice that caching plugins store generated pages according to the URL only, they ignore all other request parameters. This is why most of the caching plugins create problems when there are features which depend upon request parameters other than URL. We also faced same problem while developing a video site. Video view count and ratings were not working properly, as plugins which were providing these features were not being executed because of the caching plugin. After trying to modify already available plugins with no success we decided to develop our own caching plugin wpbase-cache, which has specific options to solve these problems.
WPBase-cache is specifically developed for varnish and nginx server stack. The plugin itself does not cache full pages, it caches database queries using db-cache-reloaded-fix plugin which is integrated in wpbase-cache after some modification. Full page caching is done by varnish and our plugin controls behavior of varnish cache by different methods. Our plugin invalidates varnish cache of a page whenever there is some changes in page content or comments section. For solving the view count problem there is a option which takes view count meta_key which is used to store views of a post in postmeta database table. We also included a specific setting option to take care of ratings and similar problems have a look at example below to understand this.
We tested this plugin for a site using video plus theme by themejunkies and wp-postratings plugin. To find meta_key for view count go to any post page and view its custom-fields where you can find a field name related to “view” word, like shown in screenshot below -
For other setting which solves rating problem open firebug console (or any other browser debugging tool you use), go to network tab and click on rating button. After clicking a xhr request will appear in network tab of debugging tolls console. Not value of “action” parameter and name of another parameter with value as post id. In example below value of action is “postratings” and name of other parameter is “pid” -
Once you have figured out these values final settings of wpbase-cache look like this -
To know more about these settings download and install wpbase-cache plugin. We have been working on this plugin to improve it and to provide other settings which can handle other major problems caused by caching pages.