Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jonswar (7880)

Journal of jonswar (7880)

Wednesday January 23, 2008
06:57 PM

CHI: Cache Interface for Perl

[ #35472 ]
CHI, a module I've been working on for a few months, has made it to CPAN:

   file: $CPAN/authors/id/J/JS/JSWARTZ/CHI-0.03.tar.gz
   size: 62313 bytes
    md5: ec828f2466ba266e11cd6d1dd5ca2913

CHI provides a unified caching API, designed to assist a developer in persisting data for a specified period of time. It is intended as an evolution of DeWitt Clinton's Cache::Cache package, adhering to the basic Cache API but adding new features and addressing limitations in the Cache::Cache implementation.

You might think of it as a fledgling "DBI for caching".

Driver classes already exist for in-process memory, plain files, memory mapped files and memcached. Other drivers such as BerkeleyDB and DBI will be coming soon. Fortunately, implementing drivers is fairly easy, on the order of creating a TIE interface to your data store.

Special thanks to the Hearst Digital Media group, where CHI was first designed and developed, for blessing the open source release of this code.

There's lots more in store for this module, so stay tuned! Feedback welcome here or on the Perl cache mailing list.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • This looks like a cool project. I particularly like the Multilevel idea.

    I've been wanting to add a caching layer to my app but one thing I've been pondering on is handling different objects in the same cache.

    I know the common solution is to prepend the object name to the key but it would be nice if this was abstracted by the cache layer itself. Perhaps an optional objectspace parameter could be added to the get/set methods? Or how about something like:

    my $cache = CHI->new( driver => 'Memory',
     

    • There is already support for multiple namespaces, but I take it that's not what you're looking for.

      I've been considering adding support for complex keys that are automatically serialized, so you could say:

      my $customer = $cache->get({customer => $name}); $cache->set({customer => $name}, $customer, "10 minutes" ); my $user = $cache->get({user => $name});

      which is maybe a little cleaner than prepending onto a string...

      • Sorry, that should have read:

        my $customer = $cache->get({customer => $name});
        $cache->set({customer => $name}, $customer, "10 minutes" );
        my $user = $cache->get({user => $name});
      • Right, I didn't want to use namespaces since that is set per cache object.

        I like the complex key idea, though.