From: Christian Hansen Date: Wed, 6 Apr 2005 11:54:27 +0000 (+0000) Subject: Changed arguments to Cache::FastMmap and config parameters X-Git-Tag: v0.01~33 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Plugin-Session-State-Cookie.git;a=commitdiff_plain;h=b2f8df5e44849b00365888e61ce49d8e8c9ef234;hp=4fbebaed5162478173fe8efda66f56885bc399be Changed arguments to Cache::FastMmap and config parameters --- diff --git a/Changes b/Changes index e11caea..acc0073 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for Perl extension Catalyst::Plugin::Session::FastMmap. +0.08 Xxx Xxx 00 00:00:00 2005 + - Fixed arguments to Cache::FastMmap. + IMPORTANT: The config parmeters has changed, backwards incompatible. 0.07 Wed Mar 28 21:17:00 2005 - Fixed urlrewrite on redirect. 0.06 Wed Mar 09 00:48:00 2005 diff --git a/FastMmap.pm b/FastMmap.pm index 1a6e6d8..b367f3a 100644 --- a/FastMmap.pm +++ b/FastMmap.pm @@ -21,6 +21,12 @@ Catalyst::Plugin::Session::FastMmap - FastMmap sessions for Catalyst =head1 SYNOPSIS use Catalyst 'Session::FastMmap'; + + MyApp->config->{session} = { + expires => 3600, + rewrite => 1, + storage => '/tmp/session' + }; $c->session->{foo} = 'bar'; print $c->sessionid; @@ -36,8 +42,8 @@ Fast sessions. =cut sub finalize { - my $c = shift; - unless ($c->config->{no_url_rewrite}) { + my $c = shift; + if ( $c->config->{session}->{rewrite} ) { my $redirect = $c->response->redirect; $c->response->redirect( $c->uri($redirect) ) if $redirect; } @@ -48,17 +54,17 @@ sub finalize { $set = 0 if $cookie->value eq $sid; } $c->response->cookies->{session} = { value => $sid } if $set; - unless ($c->config->{no_url_rewrite}) { - my $finder = URI::Find->new( - sub { - my ( $uri, $orig ) = @_; - my $base = $c->request->base; - return $orig unless $orig =~ /^$base/; - return $orig if $uri->path =~ /\/-\//; - return $c->uri($orig); - } - ); - $finder->find( \$c->res->{output} ) if $c->res->output; + if ( $c->config->{session}->{rewrite} ) { + my $finder = URI::Find->new( + sub { + my ( $uri, $orig ) = @_; + my $base = $c->request->base; + return $orig unless $orig =~ /^$base/; + return $orig if $uri->path =~ /\/-\//; + return $c->uri($orig); + } + ); + $finder->find( \$c->res->{output} ) if $c->res->output; } } return $c->NEXT::finalize(@_); @@ -107,21 +113,18 @@ sub session { =cut sub setup { - my $self = shift; - my $cache_root = $self->config->{cache_root} || tempdir; - my $default_expires_in = $self->config->{default_expires_in} - || 60 * 60 * 24; - my $auto_purge_interval = $self->config->{auto_purge_interval} - || 60 * 60 * 24; - my $auto_purge_on_set = $self->config->{auto_purge_on_set} || 1; + my $self = shift; + $self->config->{session}->{storage} ||= '/tmp/session'; + $self->config->{session}->{expires} ||= 60 * 60 * 24; + $self->config->{session}->{rewrite} ||= 0; + $self->_session( Cache::FastMmap->new( - cache_root => $cache_root, - default_expires_in => $default_expires_in, - auto_purge_interval => $auto_purge_interval, - auto_purge_on_set => $auto_purge_on_set + share_file => $self->config->{session}->{storage}, + expire_time => $self->config->{session}->{expires} ) ); + return $self->NEXT::setup(@_); } @@ -151,30 +154,18 @@ sub uri { =head2 CONFIG OPTIONS -=head3 no_url_rewrite +=head3 rewrite -To disable automatic storing of sessions in the url, -you can disable the url rewriting for session by setting -this to a true value. +To enable automatic storing of sessions in the url set this to a true value. -=head3 cache_root +=head3 storage -The root directory for the session cache. defaults to a -tempdir. +File to mmap for sharing of data, defaults to /tmp/session. -=head3 default_expires_in +=head3 expires how many seconds until the session expires. defaults to 1 day -=head3 auto_purge_interval - -How often should the system purge sessions. Defaults to 1 time -per day. - -=head3 auto_purge_on_set - -Is auto purge enabled? defaults to true. - =head1 SEE ALSO L L.