Michael A. Nachbaur > Class-DBI-Cacheable-0.03 > Class::DBI::Cacheable

Download:
Class-DBI-Cacheable-0.03.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.03   Source  

NAME ^

Class::DBI::Cacheable - Class::DBI object cache framework

SYNOPSIS ^

    package YourApp::DB;
    use base 'Class::DBI::Cacheable';
    __PACKAGE__->set_db( Main => 'dbi:Pg:dbname=database', 'username', 'password' );

DESCRIPTION ^

Class::DBI::Cacheable transparently acts as a cacheing wrapper around Class::DBI, storing retrieved and created data in a local object cache, and returning data out of the cache wherever possible.

Intended for better performance of Class::DBI-based applications, this can prevent unnecessary database queries by using previously-retrieved object data rather than having to go to the database server every time a object is retrieved.

It is highly configurable so you can customize both on an per-application and per-class basis the directory root where objects are stored, expire times, and other important parameters.

Method Reference ^

CLASS->retrieve( [args] )

This method overrides the retrieve() method of Class::DBI, and adds caching capabilities. It first constructs a cache key from the supplied arguments, and tries to retrieve that object from the data store. If a valid object is returned, that is given to the caller and the entire Class::DBI->retrieve method is bypassed.

However, in the event the object does not exist in the cache, Class::DBI is used to retrieve the object.

CLASS->construct(data)

This method overrides the construct() method of Class::DBI, which is responsible for constructing an object from searched or otherwise retrieved database data. This method circumvents this system to try and retrieve a cached object first. Next, the real construct() method is called, after which this data is then stored in the cache.

CLASS->update([args])

This simple wrapper around Class::DBI's update() method simply passes the update action on to Class::DBI, after which the object is refreshed in the cache. This ensures that, if database data is altered, the cache will always accurately reflect the database contents.

Note: this will only work properly when updates are made through Class::DBI::Cachable. If changes are made to the database via direct SQL calls the cache will be out-of-sync with the real database.

TIPS AND USAGE NOTES ^

Most customization for this package is possible by overriding the class methods exposed by Class::DBI::ObjectCache, so visit the documentation for that class to see what all can be changed and customized.

USE A DIFFERENT CACHE_ROOT FOR EACH APPLICATION

By overriding CACHE_ROOT in the base class used to connect to your database, you can indicate a separate cache directory for each of your database connections. In this way, if you need to perform debugging, you are changing database contents outside of your framework, or you simply are not certain if you have some old and tainted data in the cache, you can remove the entire directory structure to start from a clean slate.

OVERRIDE EXPIRES FOR YOUR OBJECTS

If you have data that can change often, override the EXPIRES class method in your perl modules. Anything within your framework, if your base class inherits from this module, can override EXPIRES. In fact, by putting logic inside the EXPIRES method for one of your classes, you can return different expirey times depending on the values stored in the object.

SEE ALSO ^

Class::DBI::ObjectCache, Class::DBI, Cache::Cache

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.

syntax highlighting: