Authen::Quiz::Plugin::Memcached - Plugin to which problem data of Authen::Quiz is cached.


Authen-Quiz documentation Contained in the Authen-Quiz distribution.

Index


Code Index:

NAME

Top

Authen::Quiz::Plugin::Memcached - Plugin to which problem data of Authen::Quiz is cached.

SYNOPSIS

Top

  use Authen::Quiz::FW qw/ Memcached /;

  my $q= Authen::Quiz::FW->new(
    data_folder => '/path/to/authen_quiz',
    memcached   => {
      servers=> ["127.0.0.1:11211"],
      },
    memcached_expire => 600,
    );

DESCRIPTION

Top

I think that it comes to influence the response when the problem data of Authen::Quiz is enlarged. This plugin caches the problem data with Memcached, and prevents the response from deteriorating.

The option of Memcached is passed to the constructor reading by way of Authen::Quiz::FW to use it.

Besides, the item named memcached_expire that sets the expiration date of cache can be passed. Default is 600.

When load_quiz is called by this, cache comes to be effective.

METHODS

Top

new

Constructor.

load_quiz

The method of Authen::Quiz is Obarraited and cache is effective.

cache

The cashe object is returned.

SEE ALSO

Top

Authen::Quiz, Authen::Quiz::FW, Cache::Memcached, Cache::Memcached::Fast,

http://egg.bomcity.com/wiki?Authen%3a%3aQuiz,

AUTHOR

Top

Masatoshi Mizuno <lushe&64;cpan.org>

COPYRIGHT AND LICENSE

Top


Authen-Quiz documentation Contained in the Authen-Quiz distribution.

package Authen::Quiz::Plugin::Memcached;
#
# Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>
#
# $Id: Memcached.pm 361 2008-08-18 18:29:46Z lushe $
#
use strict;
use warnings;

eval{ require Cache::Memcached::Fast };  ## no critic.
if (my $error= $@) {
	$error=~m{Can\'t\s+locate\s+Cache.+?Memcached.+?Fast}i || die $error;
	require Cache::Memcached;
	*cache= sub { $_[0]->{_cache} ||= Cache::Memcached->new($_[0]->{memcached}) };
} else {
	*cache= sub { $_[0]->{_cache} ||= Cache::Memcached::Fast->new($_[0]->{memcached}) };
}

our $VERSION= '0.01';

our $CacheKey= 'authen_quiz_plugin_memcached';

sub new {
	my $self= shift->next::method(@_);
	my $c= $self->{memcached} ||= {};
	   $c->{servers} ||= ["127.0.0.1:11211"];
	$self->{memcached_expire} ||= 600;
	$self;
}
sub load_quiz {
	my($self)= @_;
	no warnings qw/ once /;
	my $key= "${CacheKey}_$Authen::Quiz::QuizYaml";
	$self->cache->get($key) || do {
		my $data= $self->next::method;
		$self->cache->set($key=> $data, $self->{memcached_expire});
		$data;
	  };
}

1;

__END__