Update of /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10769/lib/OpenInteract2
Modified Files:
Cache.pm
Log Message:
add some sugar to get() to allow just a single argument (the key) to be passed in
Index: Cache.pm
===================================================================
RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Cache.pm,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** Cache.pm 18 Mar 2005 04:09:48 -0000 1.13
--- Cache.pm 3 Jul 2005 16:24:21 -0000 1.14
***************
*** 45,49 ****
}
! my $key = $p->{key};
my $is_object = 0;
my $obj_class = undef;
--- 45,58 ----
}
! # allow for get( $key ) and get({ key => $key }) calling methods
! my ( $key );
! if ( ref $p ) {
! $key = $p->{key};
! }
! else {
! $key = $p;
! $p = {};
! }
!
my $is_object = 0;
my $obj_class = undef;
***************
*** 57,62 ****
}
unless ( $key ) {
! $log->is_debug &&
! $log->debug( "Cache MISS (no key)" );
return undef;
}
--- 66,70 ----
}
unless ( $key ) {
! $log->is_debug && $log->debug( "Cache MISS (no key)" );
return undef;
}
***************
*** 64,74 ****
my $data = $self->get_data( $self->{_cache_object}, $key );
unless ( $data ) {
! $log->is_debug &&
! $log->debug( "Cache MISS [$key]" );
return undef;
}
! $log->is_debug &&
! $log->debug( "Cache HIT [$key]" );
if ( $is_object ) {
return undef unless ( $obj_class->post_cache_get( $data ) );
--- 72,80 ----
my $data = $self->get_data( $self->{_cache_object}, $key );
unless ( $data ) {
! $log->is_debug && $log->debug( "Cache MISS [$key]" );
return undef;
}
! $log->is_debug && $log->debug( "Cache HIT [$key]" );
if ( $is_object ) {
return undef unless ( $obj_class->post_cache_get( $data ) );
***************
*** 244,252 ****
=back
! B<get( \%params )>
Returns the data in the cache associated with a key; undef if data
corresponding to the key is not found.
B<set( \%params )>
--- 250,262 ----
=back
! B<get( $key || \%params )>
Returns the data in the cache associated with a key; undef if data
corresponding to the key is not found.
+ Note that the common case (where you just want to retrieve a cached
+ item by key) allows you to skip creating a hashref to pass in a single
+ argument.
+
B<set( \%params )>
|