NAME

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

SYNOPSIS

    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;
        $self->setCache();
    }

DESCRIPTION

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.

CACHE()

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.

EXPIRES()

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

CACHE_ROOT()

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

CACHE_DEPTH()

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

Default: 4

SEE ALSO

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

AUTHOR

Michael A Nachbaur, <mike@nachbaur.com>

COPYRIGHT AND LICENSE

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