1 package Plack::Session::Store::Cache;
6 our $AUTHORITY = 'cpan:STEVAN';
8 use Scalar::Util qw[ blessed ];
10 use parent 'Plack::Session::Store';
12 use Plack::Util::Accessor qw[ cache ];
15 my ($class, %params) = @_;
17 die('cache require get, set and remove method.')
18 unless blessed $params{cache}
19 && $params{cache}->can('get')
20 && $params{cache}->can('set')
21 && $params{cache}->can('remove');
23 bless { %params } => $class;
27 my ($self, $session_id ) = @_;
28 $self->cache->get($session_id);
32 my ($self, $session_id, $session) = @_;
33 $self->cache->set($session_id => $session);
37 my ($self, $session_id) = @_;
38 $self->cache->remove($session_id);
49 Plack::Session::Store::Cache - Cache session store
54 use Plack::Session::Store::Cache;
58 return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello Foo' ] ];
63 store => Plack::Session::Store::Cache->new(
64 cache => CHI->new(driver => 'FastMmap')
71 This will persist session data using any module which implements the
72 L<Cache> interface. This offers a lot of flexibility due to the many
73 excellent L<Cache>, L<Cache::Cache> and L<CHI> drivers available.
75 This is a subclass of L<Plack::Session::Store> and implements
82 =item B<new ( %params )>
84 The constructor expects the I<cache> param to be an object instance
85 which has the I<get>, I<set>, and I<remove> methods, it will throw an
86 exception if that is not the case.
90 A simple accessor for the cache handle.
96 All complex software has bugs lurking in it, and this module is no
97 exception. If you find a bug please either email me, or add the bug