View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Michael A. Nachbaur > Class-DBI-Cacheable-0.03 > Class::DBI::ObjectCache



Annotate this POD

View/Report Bugs
Module Version: 0.03   Source  


Class::DBI::ObjectCache - Object cache used by Class::DBI::Cacheable


    package YourClass::Name;
    use base "Class::DBI::ObjectCache";

    sub get {
        my $self = shift;
        if ($self->can('getCache')) {
            my $obj = $self->getCache(@_);
            return $obj if (defined($obj));
        # Do your magic to construct your object

    sub set {
        my $self = shift;


This method is a generic base-class used for storing and retrieving objects to and from a Cache::Cache framework. This is extended by Class::DBI::Cacheable to provide transparent Class::DBI caching support, though it can be used for other types of objects as well.

Method Reference ^

CLASS->getCacheKey( [$data] )

This method composes a unique key to represent this cache with. This is used when storing the object in the cache, and for later retrieving it.

CLASS->getCache( $key )

This method attempts to retrieve an object with the given key from the cache. Returns undef if no valid value exists, or if the supplied key is invalid.

$obj->setCache( [$key] )

Store this object in the cache with the optionally supplied key. If no key is supplied, one is computed automatically.

$obj->removeCache( [$key] )

Remove this object from the cache with the optionally supplied key. If no key is supplied, one is computed automatically.


Class method that stores and returns Cache::Cache objects.

Note: This implementation uses Cache::FileCache to store objects in the cache framework. If you want to use some other back-end cache store, like a database or shared memory, subclass this class and override this method.


Indicates the default expire time for any object stored in the cache. Override this in your subclass to indicate specific expirey times.

Since this method is invoked every time an object is added to the datastore, you can return different expire durations on a per-object basis, simply by implementing some logic in this method.

Default: 600 seconds


Indicates the directory where objects will be stored on disk. Override this if you wish different applications, classes or sets of classes to be stored in their own cache directory.

Default: /tmp/Object-Cache


Indicates the directory depth that will be created for storing cached files.

Default: 4


Class::DBI::Cacheable, Cache::Cache, Cache::FileCache


Michael A Nachbaur, <>


This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: