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" );
30 my ( $class, $c_type ) = @_;
31 return undef unless $c_type;
33 return $caches{$c_type} if exists $caches{$c_type};
34 return $caches{$c_type} = $class->new( $c_type );
41 my( $class, $c_type ) = @_;
42 return undef unless $c_type;
44 return $caches{$c_type} if exists $caches{$c_type};
46 $class = ref( $class ) || $class;
48 my $config = OpenSRF::Utils::Config->current;
49 my $cache_servers = $config->mem_cache->$c_type;
51 my $instance = Cache::Memcached->new( { servers => $cache_servers } );
53 return bless( $instance, $class );