Class::Cache

Object factory with revivifying cache
Download

Class::Cache Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Publisher Name:
  • Terrence Brannon
  • Publisher web site:
  • http://search.cpan.org/~tbone/

Class::Cache Tags


Class::Cache Description

Object factory with revivifying cache Developer commentsIn mod_perl, one wants to pre-load as many things as possible. However, the objects created from the classes that I was loading can only be used once, after which they have to be recreated. So, to save oneself the trouble of keeping track of which class instances have been used and then writing code to re-vivify them, the Class::Cache Perl module handles that.SYNOPSIS use Class::Cache; my $class_cache = Class::Cache->new( # expire cache items when retrieved (on_get). The other option is # to never expire them, by setting this key's value to 0. Timed # expiry is not implemented or entirely expected in the application # domain of this module. expires => 'on_get', # default constructor is new for items constructed by simple_* call new => 'new', # call the constructor eagerly? lazy => 0, # constructor takes no args by default args => [], # IMPORTANT: # There is *_NO_* default package for object construction. If the # key C does not exist in the configuration hash for a cache # item, then it is assumed that the cache item key is the package # name ); # All ofthe above constructor parms are the defaults, so the same # Class::Cache could have been created via Class::Cache->new(); # Key and package are assumed to have the same name if "pkg" is not # part of the configuration hashref. Therefore, in this case # constructor name is "build". Do not expire this cache entry. $class_cache->set( 'html::footer' => { new => 'build', expires => 0 }, ); # Here, key and package have the same name. Constructor is new and we # supply args for it: $class_cache->set( 'Class::Cache::Adder' => { args => }, ) # key and package same name, constructor is new, takes no args $class_cache->set( 'Super::SimpleClass' => 1, ); $class_cache->set( # key is lazy_adder, lazily call as Lazy->Adder->new(1,2,3); lazy_adder => { lazy => 1, pkg => 'Lazy::Adder', args => } ); # Write a constructor as opposed to having this module build it. # Do not forget to use or require the module you need for your # custom factory to work! $class_cache->set( compo => { lazy => 1, new => sub { my $pkg = 'Uber::Super::Cali::Fragi::Listic::Complex::Package'; my $x = $pkg->this; $pkg->that; $pkg->give_object; } } ); Requirements: · Perl


Class::Cache Related Software