Skip to content
Browse files

Plugin::Session で expire 指定可能に

  • Loading branch information...
1 parent 248b452 commit 7aa75a2cd862202dd9fbd74f4da59e4dfb2e27a8 @fujiwara fujiwara committed Sep 2, 2011
Showing with 25 additions and 2 deletions.
  1. +6 −0 lib/Ark/Plugin/Session/Backend.pm
  2. +6 −2 lib/Ark/Plugin/Session/Store/Model.pm
  3. +13 −0 t/plugin_session_model.t
View
6 lib/Ark/Plugin/Session/Backend.pm
@@ -35,6 +35,12 @@ has digest_model => (
isa => 'Str',
);
+has expire => (
+ is => "rw",
+ isa => "Int",
+ default => 0,
+);
+
after $_ => sub { shift->session_updated(1); }
for qw/get set remove/;
View
8 lib/Ark/Plugin/Session/Store/Model.pm
@@ -38,8 +38,12 @@ around 'set_session_data' => sub {
my ($self, $key, $value) = @_;
$key = $self->store_model_key_prefix . $key;
- $self->store_model->set( $key, $value );
-
+ if ( my $expire = $self->expire ) {
+ $self->store_model->set( $key, $value, $expire );
+ }
+ else {
+ $self->store_model->set( $key, $value );
+ }
$next->(@_);
};
View
13 t/plugin_session_model.t
@@ -14,6 +14,10 @@ plan skip_all => 'Cache::MemoryCache required to run this test' if $@;
Session::Store::Model
/;
+ conf 'Plugin::Session' => {
+ expire => 3,
+ };
+
conf 'Plugin::Session::Store::Model' => {
model => 'Session',
};
@@ -97,3 +101,12 @@ use Ark::Test 'T1',
{
is(get('/prefix'), 'key_prefix_of_session:', 'specified prefix used');
}
+
+{
+ request(GET => '/test_set');
+ is(get('/test_get'), 'testdata', 'session get ok');
+ sleep 1;
+ is(get('/test_get'), 'testdata', 'session get after 1sec ok');
+ sleep 3;
+ is(get('/test_get'), '', 'session expired ok');
+}

0 comments on commit 7aa75a2

Please sign in to comment.
Something went wrong with that request. Please try again.