< WhatWebWhat Search >

Depcached - memcache(d) with dependencies

When using memcache we bumped into some problems. The major one was that we needed to invalidate data due to some content that was updated. For this we took a fresh look at memcache, and made our own derivative, depcached. Short for Dependency Cache.

It is available for all to download and use. Version 1.0.1 and newer now also supports simple queues. Will document it a bit better soon...

Please note that the PHP extension was missing in the 1.0.1 release. You can download the 1.0.2 release when you want to use it.

Click to download: depcached 1.0.2 145.7 KB Click to download: Anymeta_Cache.php 8.4 KB Click to download: GPL version 2 17.6 KB

In the depcached tar we also included the code for the php client. Just use phpize, configure and make install to install the client. Don't forget to adapt your php.ini to load it as an extension.

We also provide the Anymeta_Cache.php source code.

How to use depcached

Depcached is very similar to memcache. Though at the moment depcached only supports a subset of the command set of memcache.

We support:

  • set key locked exptime datasz dep-keys
  • get key
  • delete key exptime
  • flush_all
  • flush key
  • queue key queue-len locked exptime datasz dep-keys
  • dequeue key
  • version
  • quit
  • stats

Queues in depcached

Queues are simple fifo queues with a fixed size. With the queue command you can add something to a queue. The get command will return you the complete queue. The dequeue command will send the oldest item in the queue and will afterwards remove it from the queue.

With every queue command you can change the length of the queue.

At the moment there is no option to get the number of items in a queue.

A small example

<?php

$depcached = depcached_connect('localhost', 31307);

if ($depcached) 
{
    $depcached->set("str_key", "String to store in depcached");
    $depcached->set("num_key", 123);

    $object = new StdClass;
    $object->attribute = 'test';
    $depcached->set("obj_key", $object);

    $array = Array('assoc'=>123, 345, 567);
    $depcached->set("arr_key", $array);

    echo '<pre>';
    var_dump($depcached->get('str_key'));
    var_dump($depcached->get('num_key'));
    var_dump($depcached->get('obj_key'));
    var_dump($depcached->get('arr_key'));
    

    $depcached->set("a/b/c", "Some value for a/b/c", 0, 0, "x y");
    var_dump($depcached->get('a/b/c'));

    $depcached->flush("x");
    var_dump($depcached->get('a/b/c'));

    $depcached->set('x', 'hello world');
    $depcached->delete('x');
}
else
{
    echo "Connection to depcached failed";
}

?>

Articles Friday, August 10, 2007