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; $self->setCache(); }
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.
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.
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.
Store this object in the cache with the optionally supplied key. If no key is supplied, one is computed automatically.
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, <mike@nachbaur.com>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Class::DBI::Cacheable, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::DBI::Cacheable
CPAN shell
perl -MCPAN -e shell install Class::DBI::Cacheable
For more information on module installation, please visit the detailed CPAN module installation guide.