1 package OpenSRF::Utils::Cache;
2 use strict; use warnings;
3 use base qw/Cache::Memcached OpenSRF/;
5 use OpenSRF::Utils::Config;
8 =head OpenSRF::Utils::Cache
10 This class just subclasses Cache::Memcached.
11 see Cache::Memcached for more options.
13 The value passed to the call to current is the cache type
14 you wish to access. The below example sets/gets data
15 from the 'user' cache.
17 my $cache = OpenSRF::Utils::Cache->current("user");
18 $cache->set( "key1", "value1" [, $expire_secs ] );
19 my $val = $cache->get( "key1" );
28 # return a named cache if it exists
30 my ( $class, $c_type ) = @_;
31 return undef unless $c_type;
32 return $caches{$c_type} if exists $caches{$c_type};
33 return $caches{$c_type} = $class->new( $c_type );
37 # create a new named memcache object.
40 my( $class, $cache_type, $servers ) = @_;
41 return undef unless $cache_type;
43 return $caches{$cache_type} if exists $caches{$cache_type};
45 $class = ref( $class ) || $class;
46 my $instance = Cache::Memcached->new( { servers => $servers } );
47 $caches{$cache_type} = $instance;
48 return bless( $instance, $class );