Egg::Model::Session::Base::FileCache - Session management by Cache::FileCache.


Egg-Plugin-SessionKit documentation Contained in the Egg-Plugin-SessionKit distribution.

Index


Code Index:

NAME

Top

Egg::Model::Session::Base::FileCache - Session management by Cache::FileCache.

SYNOPSIS

Top

  package MyApp::Model::Sesion;

  __PACKAGE__->config(
   filecache => {
     cache_root         => MyApp->path_to('cache'),
     namespace          => 'sessions',
     cache_depth        => 3,
     default_expires_in => (60* 60),
     },
   );

  __PACKAGE__->startup(
   Base::FileCache
   ID::SHA1
   Bind::Cookie
   );

DESCRIPTION

Top

The session data is preserved by using Cache::FileCache.

And, 'Base::DBI' is added to startup of the component module generated with Egg::Helper::Model::Session. Default is this module.

There is no Store system component needing because Cache::FileCache can treat HASH well.

  __PACKAGE__->startup(
   Base::FileCache
   ID::SHA1
   Bind::Cookie
   );

CONFIGURATION

Top

'filecache' key is set to config of the session component module.

  __PACKAGE__->config(
   filecache => {
    .......
    },
   );

All set items are passed to Cache::FileCache.

see Cache::FileCache.

METHODS

Top

Because most of these methods is the one that Egg::Model::Session internally uses it, it is not necessary to usually consider it on the application side.

cache

The Cache::FileCache object is returned.

restore ([SESSION_ID])

The session data obtained by received SESSION_ID is returned.

When SESSION_ID is not obtained, it acquires it in 'Session_id' method.

insert ([SESSION_DATA], [SESSION_ID])

New session data is preserved.

SESSION_DATA is indispensable.

When SESSION_ID is not obtained, it acquires it in 'Session_id' method.

update ([SESSION_DATA], [SESSION_ID])

The same processing as 'insert' is done.

delete ([SESSION_ID])

The session data is deleted.

SESSION_ID is indispensable.

  $session->delete('abcdefghijkemn12345');

SEE ALSO

Top

Egg::Release, Egg::Model::Session, Egg::Model::Session::Manager::Base, Egg::Model::Session::Manager::TieHash, Egg::Model, Cache::FileCache,

AUTHOR

Top

Masatoshi Mizuno <lushe&64;cpan.org>

COPYRIGHT AND LICENSE

Top


Egg-Plugin-SessionKit documentation Contained in the Egg-Plugin-SessionKit distribution.

package Egg::Model::Session::Base::FileCache;
#
# Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>
#
# $Id: FileCache.pm 256 2008-02-14 21:07:38Z lushe $
#
use strict;
use warnings;
use Cache::FileCache;
use Carp qw/ croak /;

our $VERSION= '3.00';

sub cache { $_[0]->attr->{cache} }

sub _setup {
	my($class, $e)= @_;
	my $c= $class->config->{filecache} ||= {};
	$c->{cache_root} ||= $e->config->{dir}{cache};
	$c->{namespace}  ||= do {
		my $pkg= ref($class) || $class;
		$pkg=~m{([^\:]+)\:+[^\:]+$};
		"session_". lc($1);
	  };
	$c->{cache_depth} ||= 3;
	$c->{default_expires_in} ||= 60* 60;
	$class->next::method($e);
}
sub TIEHASH {
	my $self= shift->next::method(@_);
	$self->attr->{cache}=
	      Cache::FileCache->new($self->config->{filecache});
	$self;
}
sub restore {
	my $self= shift;
	my $id  = shift || $self->session_id || croak q{I want session id.};
	$self->cache->get($id) || 0;
}
sub insert {
	my $self= shift;
	my $data= shift || croak q{I want session data.};
	my $id  = shift || $self->session_id || croak q{I want session id.};
	$self->cache->set($id, $data);
}
*update= \&insert;

sub delete {
	my $self= shift;
	my $id= shift || croak q{I want session id.};
	$self->cache->remove($id);
	$self;
}

1;

__END__