1 package Plack::Session::Store::CHI;
5 use Scalar::Util qw/blessed/;
7 use parent 'Plack::Session::Store';
9 use Plack::Util::Accessor qw[ chi ];
12 my ($class, %params) = @_;
13 unless ( blessed $params{chi} and $params{chi}->isa('CHI::Driver') ) {
14 die('require chi driver');
16 bless { %params } => $class;
20 my ($self, $session_id, $key) = @_;
21 my $cache = $self->chi->get($session_id);
23 return $cache->{ $key };
27 my ($self, $session_id, $key, $data) = @_;
28 my $cache = $self->chi->get($session_id);
30 $cache = {$key => $data};
33 $cache->{$key} = $data;
35 $self->chi->set($session_id => $cache);
39 my ($self, $session_id, $key) = @_;
40 my $cache = $self->chi->get($session_id);
41 return unless exists $cache->{$key};
43 delete $cache->{ $key };
44 $self->chi->set($session_id => $cache);
48 my ($self, $session_id) = @_;
49 $self->chi->remove($session_id);
60 Plack::Session::Store::CHI - CHI session store
65 use Plack::Session::Store::CHI;
69 return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello Foo' ] ];
74 store => Plack::Session::Store::CHI->new(
75 chi => CHI->new(driver => 'FastMmap')
82 This is a subclass of L<Plack::Session::Store> and implements
89 =item B<new ( %params )>
91 The constructor expects an the I<chi> param to be an
92 instance of L<CHI::Driver>, it will throw an exception
93 if that is not the case.
101 All complex software has bugs lurking in it, and this module is no
102 exception. If you find a bug please either email me, or add the bug