From b9a41ff1f54f07e1d3060e37e15be852d0495447 Mon Sep 17 00:00:00 2001 From: Chris Hall Date: Mon, 21 Nov 2011 11:38:23 +1300 Subject: [PATCH] [SIGNED-OFF] Bug 7248 Added caching support and and moved Caching into Koha namespace Signed-off-by: Jared Camins-Esakov Signed-off-by: Katrin Fischer --- C4/Cache/Memoize/Memcached.pm | 57 --------------------------------------- {C4 => Koha}/Cache.pm | 23 ++++++++-------- {C4 => Koha}/Cache/Memcached.pm | 13 +++++---- t/Cache.t | 2 +- t/Cache_Memcached.t | 2 +- t/Cache_Memoize_Memcached.t | 14 ---------- 6 files changed, 19 insertions(+), 92 deletions(-) delete mode 100644 C4/Cache/Memoize/Memcached.pm rename {C4 => Koha}/Cache.pm (72%) rename {C4 => Koha}/Cache/Memcached.pm (86%) delete mode 100755 t/Cache_Memoize_Memcached.t diff --git a/C4/Cache/Memoize/Memcached.pm b/C4/Cache/Memoize/Memcached.pm deleted file mode 100644 index c65e8a6..0000000 --- a/C4/Cache/Memoize/Memcached.pm +++ /dev/null @@ -1,57 +0,0 @@ -package Koha::Cache::Memoize::Memcached; - -# Copyright 2009 Chris Cormack and The Koha Dev Team -# -# This file is part of Koha. -# -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 2 of the License, or (at your option) any later -# version. -# -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with Koha; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -use strict; -use warnings; -use Carp; - -use Memoize::Memcached; - -use base qw(C4::Cache); - -sub _cache_handle { - my $class = shift; - my $params = shift; - - my @servers = split /,/, $params->{'cache_servers'}; - - my $memcached = { - servers => \@servers, - key_prefix => $params->{'namespace'} || 'koha', - }; - my $cache = {}; - $cache->{memcache}=$memcached; - return $cache; -} - -sub memcached_memoize { - my $self = shift; - my $function = shift; - my $ttl = shift; - memoize_memcached($function, memcached => $self->{memcached}, expire_time => $ttl); -} - -1; -__END__ - -=head1 NAME - -C4::Cache::Memoize::Memcached - subclass of C4::Cache - -=cut diff --git a/C4/Cache.pm b/Koha/Cache.pm similarity index 72% rename from C4/Cache.pm rename to Koha/Cache.pm index 151a3fa..25aad93 100644 --- a/C4/Cache.pm +++ b/Koha/Cache.pm @@ -1,4 +1,4 @@ -package C4::Cache; +package Koha::Cache; # Copyright 2009 Chris Cormack and The Koha Dev Team # @@ -19,15 +19,15 @@ package C4::Cache; =head1 NAME -C4::Cache - Handling caching of html and Objects for Koha +Koha::Cache - Handling caching of html and Objects for Koha =head1 SYNOPSIS - use C4::Cache (cache_type => $cache_type, %params ); + use Koha::Cache (cache_type => $cache_type, %params ); =head1 DESCRIPTION -Base class for C4::Cache::X. Subclasses need to provide the following methods +Base class for Koha::Cache::X. Subclasses need to provide the following methods B<_cache_handle ($params_hr)> - cache handle creator @@ -49,19 +49,18 @@ use Carp; use base qw(Class::Accessor); -use C4::Cache::Memcached; +use Koha::Cache::Memcached; __PACKAGE__->mk_ro_accessors( qw( cache ) ); sub new { - my $class = shift; - my %param = @_; - - my $cache_type = $param{cache_type} || 'memcached'; + my $class = shift; + my $param = shift; + my $cache_type = $param->{cache_type} || 'memcached'; my $subclass = __PACKAGE__."::".ucfirst($cache_type); - my $cache = $subclass->_cache_handle(\%param) + my $cache = $subclass->_cache_handle($param) or croak "Cannot create cache handle for '$cache_type'"; - return bless $class->SUPER::new({cache => $cache}), $subclass; + return bless $class->SUPER::new({cache => $cache}), $subclass; } =head2 EXPORT @@ -70,7 +69,7 @@ None by default. =head1 SEE ALSO -C4::Cache::Memcached +Koha::Cache::Memcached =head1 AUTHOR diff --git a/C4/Cache/Memcached.pm b/Koha/Cache/Memcached.pm similarity index 86% rename from C4/Cache/Memcached.pm rename to Koha/Cache/Memcached.pm index 1233d41..87fe3c7 100644 --- a/C4/Cache/Memcached.pm +++ b/Koha/Cache/Memcached.pm @@ -1,4 +1,4 @@ -package C4::Cache::Memcached; +package Koha::Cache::Memcached; # Copyright 2009 Chris Cormack and The Koha Dev Team # @@ -23,14 +23,12 @@ use Carp; use Cache::Memcached; -use base qw(C4::Cache); +use base qw(Koha::Cache); sub _cache_handle { my $class = shift; my $params = shift; - my @servers = split /,/, $params->{'cache_servers'}; - return Cache::Memcached->new( servers => \@servers, namespace => $params->{'namespace'} || 'KOHA', @@ -40,6 +38,7 @@ sub _cache_handle { sub set_in_cache { my ( $self, $key, $value, $expiry ) = @_; croak "No key" unless $key; + $self->cache->set_debug; if ( defined $expiry ) { return $self->cache->set( $key, $value, $expiry ); @@ -67,10 +66,10 @@ sub flush_all { } 1; -__END__ - +__END__ + =head1 NAME -C4::Cache::Memcached - memcached subclass of C4::Cache +Koha::Cache::Memcached - memcached subclass of Koha::Cache =cut diff --git a/t/Cache.t b/t/Cache.t index 75f5acf..dca575b 100644 --- a/t/Cache.t +++ b/t/Cache.t @@ -9,6 +9,6 @@ use warnings; use Test::More tests => 1; BEGIN { - use_ok('C4::Cache'); + use_ok('Koha::Cache'); } diff --git a/t/Cache_Memcached.t b/t/Cache_Memcached.t index 80dfc7f..a9366cc 100755 --- a/t/Cache_Memcached.t +++ b/t/Cache_Memcached.t @@ -9,6 +9,6 @@ use warnings; use Test::More tests => 1; BEGIN { - use_ok('C4::Cache::Memcached'); + use_ok('Koha::Cache::Memcached'); } diff --git a/t/Cache_Memoize_Memcached.t b/t/Cache_Memoize_Memcached.t deleted file mode 100755 index 13e26e5..0000000 --- a/t/Cache_Memoize_Memcached.t +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/perl -# -# This Koha test module is a stub! -# Add more tests here!!! - -use strict; -use warnings; - -use Test::More tests => 1; - -BEGIN { - use_ok('C4::Cache::Memoize::Memcached'); -} - -- 1.7.9.5