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 https://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)
  • cache just for readers and not for admin’s or users to avoid html fragments that should be not displayed on the readers view

goto: project page

goto: download version 1.0.0

4 comments

  • Comment by Martin
    March 15th, 2011 at 12:46 pm

    Nice project, but how do you handle post requests? When i write a comment, it will always post to the same url. If I understand your description right, i can only do one comment and every other comment will be dropped because the cache file for this url is allready there and so the wordpress process will not be started.

    Martin

  • Comment by Alex
    March 15th, 2011 at 8:31 pm

    Hej Martin,

    i think there is a little misunderstanding. Of course, the comment handling works well, if you have a small TTL. The routine that performs your comment-request goes a different route, then the simple page request does (For instance on this page: https://cip-labs.net/wp-comments-post.php). After the TTL expires, the cache file would be, simply, overwritten.

    This project is a very simple and stupid cache. But, it was necessary to serve a high amount (with high concurrency) of requests on a client blog. The obvious solution was to serve the files static and that was the reason of development.

    The simple Wordpress cache is also a part of Speedpress. This is also a project of cip-labs. It is a Wordpress system that contains approx. 20 hacks, extensions and improvements to make Wordpress faster.

    It will be published in summer 2011 together with a new cms performance report.

    Stay tuned && regards!
    Alex

  • Comment by ケイトスペード 財布 新作 2014
    May 25th, 2014 at 10:30 pm

    Great post! We will be linking to this great content on our website. Keep up the good writing.|
    ケイトスペード 財布 新作 2014 http://www.revolutionize.us

  • Comment by victoria secret france
    July 28th, 2014 at 2:23 am

    A simple cache for Wordpress » cip-labs – Coding, Databases & Artificial Intelligence
    victoria secret france http://www.demoiselledhonneur.fr/

Comments:

XHTML: You can use the following tags: