| Apache-XPP documentation | Contained in the Apache-XPP distribution. |
Apache::XPP::Cache - XPP Cache manegment module
use Apache::XPP::Cache; $cache = Apache::XPP::Cache->new( %options ); $cache = Apache::XPP::Cache->is_cached( %options );
Apache::XPP
Nothing
Apache::XPP::Cache is an interface to both Store and Expire caching modules.
Creates a new Cache object using the specified Store and Expire types.
install_module ( ('Store'|'Expiry'), $name )Installs the $name store or expiry module, and returns the associated class name.
is_expired ( )Returns a true value if the current cache has expired, otherwise returns false.
content ( )Returns the content of the current cache.
r ( )Returns the Apache request object
AUTOLOAD ( )Calling $obj->meth() returns $obj->{'meth'}. Calling $obj->meth($val) sets $obj->{'meth'} = $val.
$Log: Cache.pm,v $ Revision 1.9 2002/01/16 21:06:01 kasei Updated VERSION variables to 2.01 Revision 1.8 2000/09/15 22:02:37 dougw Took out $AUTOLOAD Revision 1.7 2000/09/15 21:35:22 dougw Autoload changed to use Apache::XPP's autoload. This didn't make it into the previous check in. Revision 1.6 2000/09/13 21:02:11 dougw David cleaned up the loop in new() so it isn't 2 identical loops. r() and AUTOLOAD() are now just forwarders to Apache::XPP::r and Apache::XPP::AUTOLOAD Revision 1.5 2000/09/07 19:03:19 dougw over fix Revision 1.4 2000/09/07 18:40:38 dougw Pod updates.
Doug Weimer <dougw@cnation.com> Greg Williams <greg@cnation.com>
l<perl(1)>. l<Apache::XPP>
| Apache-XPP documentation | Contained in the Apache-XPP distribution. |
# Apache::XPP::Cache # -------------------- # $Revision: 1.9 $ # $Date: 2002/01/16 21:06:01 $ #-----------------------------
package Apache::XPP::Cache;
use Carp; use strict; use vars qw( $debug $debuglines ); BEGIN { $Apache::XPP::Cache::REVISION = (qw$Revision: 1.9 $)[-1]; $Apache::XPP::Cache::VERSION = '2.01'; $debug = undef; $debuglines = 1; }
{# BEGIN PRIVATE CODE BLOCK my %cache; sub new { # Apache::XPP::Cache->new( 're4sidebar', 'games', { r => $r }, [ 'File', $content ], [ 'Duration', '2h' ] ); my $proto = shift; my $class = ref($proto) || $proto; my $name = shift; my $group = shift; my $instance = shift; my $self; my $specifier = unpack("%32C*", $name . $group) % 65535; if ($cache{ $specifier }) { warn "cache: using cached object (in new)" . ($debuglines ? '' : "\n") if ($debug); $self = $cache{ $specifier }; } else { warn "cache: creating new object (in new)" . ($debuglines ? '' : "\n") if ($debug); my $store = shift; my $expire = shift; $self = bless( { %{ ref($instance) ? $instance : {} } }, $class ); foreach my $part ( {Store => $store}, {Expire => $expire} ) { my ($label, $inputs) = %{$part}; my $type = shift( @{ $inputs } ); if (my $thisclass = $class->install_module( (($label eq 'Expire') ? 'Expiry' : $label), $type )) { my $obj = $thisclass->new( $name, $group, { r => $self->r }, @{ $inputs } ); if (ref($obj)) { my $meth = $label . 'Type'; $self->$meth( $type ); # StoreType/ExpireType $meth = $label . 'Object'; $self->$meth( $obj ); # StoreObject/ExpireObject } else { return undef; } } else { carp "Specified $label type ($type) is not registered as available!"; return undef; } } $cache{ $specifier } = $self; } } # END constructor new } # END private code block for %cache
sub install_module { # shamelessly snagged from DBI my $class = shift; my $type = shift; my $name = shift; $type = 'Expiry' unless ($type eq 'Store'); my $mod; # already installed return $mod if ($mod = $Apache::XPP::installed{ $type }{ $name }); # --- load the code $mod = "Apache::XPP::Cache::${type}::${name}"; eval "package Apache::XPP::Cache::_firesafe; require $mod"; if ($@) { warn "require of ($mod) failed! $@"; return undef; } $Apache::XPP::installed{ $type }{ $name } = $mod; } sub store { my $self = shift; return undef unless ref($self); return $self->{ 'StoreObject' }; } # END method store sub expire { my $self = shift; return undef unless ref($self); return $self->{ 'ExpireObject' }; } # END method expire
sub is_expired { my $self = shift; return undef unless ref($self); if ($self->expire->is_expired( $self->store )) { $self->store->is_expired; return 1; } else { return 0; } } # END method is_expired
sub content { my $self = shift; return ref($self) ? $self->store->content : undef; } # END method content
*r = \&{ "Apache::XPP::r" };
*AUTOLOAD = \&{ "Apache::XPP::AUTOLOAD" }; 1; __END__