fix some typos and spelling mistakes
[catagits/Web-Session.git] / lib / Plack / Session / Store / Cache.pm
1 package Plack::Session::Store::Cache;
2 use strict;
3 use warnings;
4
5 our $VERSION   = '0.11';
6 our $AUTHORITY = 'cpan:STEVAN';
7
8 use Scalar::Util qw[ blessed ];
9
10 use parent 'Plack::Session::Store';
11
12 use Plack::Util::Accessor qw[ cache ];
13
14 sub new {
15     my ($class, %params) = @_;
16
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');
22
23     bless { %params } => $class;
24 }
25
26 sub fetch {
27     my ($self, $session_id ) = @_;
28     $self->cache->get($session_id);
29 }
30
31 sub store {
32     my ($self, $session_id, $session) = @_;
33     $self->cache->set($session_id => $session);
34 }
35
36 sub remove {
37     my ($self, $session_id) = @_;
38     $self->cache->remove($session_id);
39 }
40
41 1;
42
43 __END__
44
45 =pod
46
47 =head1 NAME
48
49 Plack::Session::Store::Cache - Cache session store
50
51 =head1 SYNOPSIS
52
53   use Plack::Builder;
54   use Plack::Session::Store::Cache;
55   use CHI;
56
57   my $app = sub {
58       return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello Foo' ] ];
59   };
60
61   builder {
62       enable 'Session',
63           store => Plack::Session::Store::Cache->new(
64               cache => CHI->new(driver => 'FastMmap')
65           );
66       $app;
67   };
68
69 =head1 DESCRIPTION
70
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.
74
75 This is a subclass of L<Plack::Session::Store> and implements
76 its full interface.
77
78 =head1 METHODS
79
80 =over 4
81
82 =item B<new ( %params )>
83
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.
87
88 =item B<cache>
89
90 A simple accessor for the cache handle.
91
92 =back
93
94 =head1 BUGS
95
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
98 to cpan-RT.
99
100 =head1 AUTHOR
101
102 Masahiro Chiba
103
104 =cut