Simple WordPress Cache

WordPress. A word that stands for an established system, a nice backend to write and edit articles but also for a frontend which performs slow and heavy. On cip-labs I developed a cache for this system. The cache is very easy to install and does the caching in a very very simple way.

How it works

It works quite simple. I had modified the index.php of the wordpress installation. When a request comes in,  an object of CIP_WP_Cache would be created. This object represents the cache. It looks up in the cache directory and tries to find the file which is requested. The files were stored in a directory defined in CIP_CACHE_DIR. If the file was found in cache (files are named like md5($_SERVER[‘REQUEST_URI’])), the cache will responds it and then shutdown. The benefit of doing so is, that the wordpress engine would never reached during the whole request. But if the file was not found in the cache, the CIP_WP_Cache captures the output buffer of the wordpress engine and stores the result in it’s cache. For the next requests to this URI, the cache responds the file from the cache.

That’s it, it does nothing more or less. Of course, you need more functionality to control the cache and I will write a plugin for WordPress which allows you to control the behavior of the cache. In the following I have a few benchmark results from my recent tests:

Benchmark

The results of the benchmark are clear. The heavy wordpress engine (avg. 13 MB ram usage) battles against a static file. I used ab -n 1000 -c http://www.cip-labs.net/ to test the performance of the cache. I think the specifiation of the benchmark environment is regardless for this benchmark.

without cip-cache

  • time taken for requests: 311.653 sec
  • requests per second: 3.21

with cip-cache

  • time taken for requests: 1.897 sec
  • requests per second: 526.88

To sum up this benchmark you can see, that cip-cache serves faster. The cache works with a TTL directive (called CIP_CACHE_TTL), which you can configure in the cip-wp.php file. When cip-cache creates the cache file, it runs through the wordpress engine and after that, it writes the output buffer to the cache directory.

How to Install

At first, you have to overwrite the index.php from your WordPress installation with the index.php from the source package (copy both files (cip-wp.php and index.php) into the directory which includes the index.php). The second step is to configure the cache with the CIP_CACHE_DIR and CIP_CACHE_TTL directives. Create a directory for the cached files and make sure, that you have set all required permissions (777).

  • CIP_CACHE_DIR: should be the directory that includes the generated cache files
  • CIP_CACHE_TTL:  time to life (in seconds)

That’s it.

Wishlist

  • control the cache behavior with a small WordPress plugin (clear cache [item or all], set TTL, set cache dir, add/remove routes to control paths to cache)
  • support of SHM (shared memory segment)
  • consider a TTL alternative
  • establish Speedpress, with any extensions in code base, engine and database structure controllable with a plugin

Versions

  • 1.1.0 – {don’t caches preview pages & admins pages} [download]

Download

2 thoughts on “Simple WordPress Cache

  1. Next week we will start to review the greatest names in Internet Radio Networks applying Stickam.

    If you spent Pat Benatar, for example, you will probably receive more songs using a strong female vocal
    lead. Baofang radio You may also pay less buying bulk from a completely independent store than from a high-end
    wholesaler.

    The mountains listed below are high and magnificent, having a variety of plants and several rare animals.

    Baofeng rádió And take note and watchful of little synchronicities and answers
    however they come. Pick your genre: any decade since the 40’s,
    Rock, Country, Urban, Jazz, Blues, Dance,
    Latin, World Music (e.

Leave a Reply

Your email address will not be published. Required fields are marked *