Plugin Output Cache


Unfortunately, due to ill-health, this plugin has not been developed or supported properly for some years. It works with the latest versions of WordPress (including on this website) but could possibly conflict with any WordPress features added after 2008 — e.g. custom post types — if you use them.


This plugin provides a way for other plugins to cache their output and speed page display. Most of my plugins use the cache automatically if it is installed. The cache is cleared automatically whenever the blog content changes so that the retrieved output is always fresh.

This is version 4.0.8 download latest version. It is faster, easier to use, and also cleans up after itself when deactivated.

Installation Instructions

  1. If you are upgrading from an earlier version first deactivate the old plugin via the Plugins menu and then delete the plugin directory from your server.
  2. Upload the whole plugin folder to your /wp-content/plugins/ folder.
  3. Go to the Plugins page and activate the plugin.
  4. Go to the Manage page and switch on caching.

Usage and Options

The plugin does nothing on its own! It exists only as a helper for other plugins. However, if my other plugins are installed they will automatically have their output cached.

You can tell if the cache is working properly by looking at the source of a browser page which uses one of my plugins, e.g., Recent Posts. Underneath the output from the plugin there will be an HTML comment telling you how long the plugin took to produce its output and whether it came from cache.

If you upgrade any plugin that uses the output cache plugin remember to clear the cache or you will not see the results of the change. The Plugin Output Cache installs a page under the admin Manage menu with a button to clear the cache and a button to switch caching on and off.

The Manage page also give you the option to collect data on how efficient the cache is on your blog. N.B. Collecting the statistical data makes the cache about 20 times slower so it should only be done to satisfy your curiosity and not as a a matter of routine.

I have defined efficiency as the percentage of cache requests actually served from the cache. After the cache has been cleared the first requests are for items that have not yet been cached and efficiency will be poor but as repeat requests are made the efficiency rises rapidly. In my experiments 85% – 95% are common. Of course every time someone makes a comment the cache is cleared and the efficiency drops again.

How to Use Plugin Output Cache for your Plugins

The Plugin Output Cache can be used by other plugins which produce output by making minor changes to them.

The Plugin Output Cache defines a constant POC_CACHE so you can check if the cache is available. Version 4.0+ also defines POC_CACHE_4 which lets you take advantage of version 4’s new features. Plugins adapted to work with earlier versions will continue to function normally.

The Recent Posts plugin shows in detail how to do it incorporate caching. The outline is as follows. Instead of:

function your_plugin() {
	$result = get_plugin_output();
	echo $result;


function your_plugin() {
	if (defined('POC_CACHE_4')) {;
		// $key is some unique string to identify the output
		$result = poc_cache_fetch($cache_key);	
		if ($result !== false) echo $result;
	$result = get_plugin_output();
	if (defined('POC_CACHE_4')) poc_cache_store($cache_key, $result); 
	echo $result;

Note: This presumes your plugin can be written to return its output as a string or signal failure by returning ‘false’.

Your code should also clear the cache whenever your plugin’s options are updated.

	if (defined('POC_CACHE_4')) poc_cache_flush();