Rose::DBx::Object::Cached::FastMmap - Rose::DB::Object Cache Cache::FastMmap
package Category; use Rose::DBx::Object::Cached::FastMmap; our @ISA = qw(Rose::DBx::Object::Cached::FastMmap); __PACKAGE__->meta->table('categories'); __PACKAGE__->meta->columns ( id => { type => 'int', primary_key => 1 }, name => { type => 'varchar', length => 255 }, description => { type => 'text' }, ); __PACKAGE__->meta->add_unique_key('name'); __PACKAGE__->meta->initialize; ... ## Defaults to default settings of L<Cache::FastMmap>. $cat1 = Category->new(id => 123, name => 'Art'); $cat1->save or die $category->error; $cat2 = Category->new(id => 123); # This will load from the cache, not the database $cat2->load or die $cat2->error; ... ## Set the cache options for all Rose::DB::Object derived objects $Rose::DBx::Object::Cached::FastMmap::SETTINGS = { root_dir => '/tmp/global_fastmmap', }; $cat1 = Category->new(id => 123, name => 'Art')->save; ## In another script $Rose::DBx::Object::Cached::FastMmap::SETTINGS = { root_dir => '/tmp/global_fastmmap', }; # This will load from the FastMmap cache, not the database $cat2 = Category->new(id => 123, name => 'Art')->load; ... ## Set cache options for all Category derived objects Category->cached_objects_settings( root_dir => '/tmp/global_fastmmap', ); ... ## Set cache expire time for all Category objects Category->cached_objects_expire_in('5 seconds');
This module intends to extend the caching ability in Rose::DB::Object allowing objects to be cached wth Cache::FastMmap. This module was created becaue of speed issues with Rose::DBx::Object::Cached::CHI. Those issues arise do to the overhead that the CHI introduces to caching of objects.
Most of the code is taken straight from Rose::DB::Object::Cached. This does not extend Rose::DB::Object::Cached because function calls and how the cache is accessed needed to be changed thoughout the code.
All objects derived from a Rose::DBx::Object::Cached::FastMmap class are set and retrieved from FastMmap, therefore 2 objects that are loaded with the same parameters are not the same code reference.
$cat1 = Category->new(id => 123, name => 'Art'); $cat1->save; $cat2-> Category->new(id => 123, name => 'Art'); $cat2->load; print $cat1->name; # prints "Art" print $cat2->name; # prints "Art" $cat1->name('Blah'); print $cat2->name; # prints "Blah"
$cat1 = Category->new(id => 123, name => 'Art'); $cat1->save; $cat2-> Category->new(id => 123, name => 'Art'); $cat2->load; print $cat1->name; # prints "Art" print $cat2->name; # prints "Art" $cat1->name('Blah'); print $cat2->name; # prints "Art"
This global is used to set FastMmap settings for all objects derived from Rose::DBx::Object::Cached::FastMmap. Any settings here will override any default settings, but will conceded to settings configured by the class method cached_objects_settings
Example:
$Rose::DBx::Object::Cached::FastMmap::SETTINGS = { root_dir => '/tmp/global_fastmmap', };
Only class methods that do not exist in Rose::DB::Object::Cached are listed here.
If called with no arguments this will return the current cache settings. PARAMS are any valid options for the Cache::FastMmap constructor.
Example: Category->cached_objects_settings ( root_dir => '/tmp/global_fastmmap', expires_in => '15m', )
Returns the default FastMmap settings for the class. This method should be implemented by a sub class if custom settings are required.
package Category; use base Rose::DBx::Object::Cached::FastMmap; ... sub default_cached_objects_settings ( return { root_dir => '/tmp/global_fastmmap', expires_in => '15 minutes', }; )
Only object methods that do not exist in Rose::DB::Object::Cached are listed here.
Calls the __xrdbopriv_clone method in Rose::DB::Object::Helpers
Because of the nature of Storable all objects set to cache are set by $object->__xrdbopriv_clone->__xrdbopriv_strip
Calls the __xrdbopriv_strip method in Rose::DB::Object::Helpers
There is most likely at better and cheaper way to do this....
Currently tests only exist for MySQL. Almost all of these have been copied directly from the tests that exist for Rose::DB::Object.
Right now you can email kmcgrath@baknet.com.
Kevin C. McGrath CPAN ID: KMCGRATH kmcgrath@baknet.com
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
perl(1).
2 POD Errors
The following errors were encountered while parsing the POD:
'=item' outside of any '=over'
You forgot a '=back' before '=head1'
To install Rose::DBx::Object::Cached::FastMmap, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Rose::DBx::Object::Cached::FastMmap
CPAN shell
perl -MCPAN -e shell install Rose::DBx::Object::Cached::FastMmap
For more information on module installation, please visit the detailed CPAN module installation guide.