Turning PHP APC on or off per site

The Alternative PHP Cache (APC) is a fantastic free and open opcode cache for PHP and does a great job at caching and optimizing PHP intermediate code. We all know what it does and how it works.
Sometimes we don’t want it enabled for all sites on a server (Using php.ini or conf.d/apc.ini), for example, you have a dev site and a live site on the same server. Having APC enabled on a dev site can be a little annoying. Continue reading “Turning PHP APC on or off per site”

Using Persistent Cache in WordPress (with APC)

Ever since WordPress 2.5, the WP Cache functions haven’t been persistent, so the cached objects are only available for the page load (or script run). This means that data stored in the cache resides in memory only and only for the duration of the request.

Upto version 2.5 we could have simply added define(‘WP_CACHE’, true) to the wp-config.php and we got persistent cache features. This is no longer the case and isn’t really very well documented.

The later versions need a Persistent Cache Plugin. I’m not a fan of some of the larger caching plugins like W3 Total Cache or WP Super Cache as they tend to add complexity and can cause other problems. Besides, as developers, we’re better off writing the code ourselves.

Before going any furuther its probably worth pointing out WordPress has two persistent caching methods.

The first method is the WP Transients API,

The second method is extending the existing WP Object Cache that is currently throughout your WordPress site already.

  • Extending this object is much more flexible
  • Can extend into APC, memcache or similar
  • Provides a fast cache for basic WordPress functions even before you write your own code

Continue reading “Using Persistent Cache in WordPress (with APC)”