OpenFrame::WebApp::Session::CacheBase - abstract base for sessions using


OpenFrame-WebApp documentation Contained in the OpenFrame-WebApp distribution.

Index


Code Index:

NAME

Top

OpenFrame::WebApp::Session::CacheBase - abstract base for sessions using Cache::Cache modules

SYNOPSIS

Top

  # abstract class - cannot be instantiated
  use base qw( OpenFrame::WebApp::Session::CacheBase );

DESCRIPTION

Top

An OpenFrame::WebApp::Session for using Cache::Cache modules.

AUTHOR

Top

Steve Purkis <spurkis@epn.nu>

Based on OpenFrame::AppKit::Session, by James A. Duncan.

COPYRIGHT

Top

SEE ALSO

Top

Cache::Cache, OpenFrame::WebApp::Sesssion, OpenFrame::WebApp::Session::MemCache, OpenFrame::WebApp::Session::FileCache


OpenFrame-WebApp documentation Contained in the OpenFrame-WebApp distribution.
package OpenFrame::WebApp::Session::CacheBase;

use strict;
use warnings::register;

use Error;
use OpenFrame::WebApp::Error::Abstract;

our $VERSION = (split(/ /, '$Revision: 1.1 $'))[1];

use base qw( OpenFrame::WebApp::Session );

sub cache_class {
    my $self = shift;
    throw OpenFrame::WebApp::Error::Abstract( class => ref($self) );
}

sub store {
    my $self   = shift;
    my $expiry = $self->get_expiry_seconds;
    my @args   = ($self->id, $self);
    push (@args, "$expiry s") if (defined $expiry);
    $self->cache_class->new()->set( @args );
    return $self->id;
}

sub fetch {
    my $class = shift;
    my $id    = shift || return;
    return $class->cache_class->new({auto_purge_on_get => 1})->get( $id );
}

sub remove {
    my $self = shift;
    my $id   = ref($self) ? $self->id : shift;
    $self->cache_class->new()->remove( $id );
    return $self;
}


1;