midgard_php_cache

Posted on 2007-04-20 10:11:51 EEST.

That's it. I finished to write 'proof of concept` midgard_php_cache. The main approach is to reuse data which are not changed among requests or are changed very very seldom.

The basic code looks like this:

$cache = new midgard_php_cache();

This is constructor so there's nothing to elaborate about.

if(!$cache->key_exists("test_key")) 
    $cache->set("test_key", "test_string");

Here I check if key exists in cache , and if it's not then I add key's value. You can do 10000000 requests at this point, set method will be invoked only once. And that's the point: I do not want to create new data over and over again.

$v = $cache->get("test_key");

And finally I get my value, using ( and knowing ) the key.

I tested only strings as this is real cache's bottleneck. It must be duplicated when value should be returned. But if you consider the fact that during every request you must create plenty of variables which will or will no be used , it then seems to be a small detail.

If I could describe cache's features I would say:

  • global data storage ( all data ara available per module )
  • no need to select data from database or from files if you need to use the same data with every request
  • integers or indexed arrays can be stored among requests without any need to initialize new data ( and thus without any need to allocate new memory for value containers )
  • file contents can be reused from cache ( even with string duplication "overhead" ) reducing I/O activity to none.
  • even as public data storage can be used for private ( or semi private ) data using unique key identifiers
  • it's written using zend so stored data are pure, typical zend ( and thus PHP's ) value containers

Back

Layout Copyright © 2006 Finnish Teleservice Center Ltd Oy - Site Powered by Midgard CMS