Bugzilla – Attachment 9567 Details for
Bug 7248
Caching for services
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 7248 follow-up (alternative)
Bug-7248-follow-up-alternative.patch (text/plain), 5.78 KB, created by
Paul Poulain
on 2012-05-14 15:30:30 UTC
(
hide
)
Description:
Bug 7248 follow-up (alternative)
Filename:
MIME Type:
Creator:
Paul Poulain
Created:
2012-05-14 15:30:30 UTC
Size:
5.78 KB
patch
obsolete
>From 0b9ecc4fd72660123ac340e5a579e36ac9143c11 Mon Sep 17 00:00:00 2001 >From: Paul Poulain <paul.poulain@biblibre.com> >Date: Mon, 14 May 2012 17:30:05 +0200 >Subject: [PATCH] Bug 7248 follow-up (alternative) > >This patch introduces some new features for caching system: >* the type of caching is retrieved from ENV variable in httpd configuration if not forced when the ->new() is called. >* if $ENV{DEBUG} is ON, you'll have feedback when something is set or read from cache >* the Koha::Cache->is_cache_active is now available and will return 1 if there is a caching system available. It's a replacement for C4::Context->ismemcached > >The 2 reports modules have been updated to use this new API >--- > Koha/Cache.pm | 8 +++++++- > Koha/Cache/Memcached.pm | 6 ++++-- > opac/svc/report | 20 ++++++-------------- > svc/report | 24 ++++++++---------------- > 4 files changed, 25 insertions(+), 33 deletions(-) > >diff --git a/Koha/Cache.pm b/Koha/Cache.pm >index 25aad93..2c1a48f 100644 >--- a/Koha/Cache.pm >+++ b/Koha/Cache.pm >@@ -56,13 +56,18 @@ __PACKAGE__->mk_ro_accessors( qw( cache ) ); > sub new { > my $class = shift; > my $param = shift; >- my $cache_type = $param->{cache_type} || 'memcached'; >+ my $cache_type = $ENV{CACHING_SYSTEM} || $param->{cache_type} || 'memcached'; > my $subclass = __PACKAGE__."::".ucfirst($cache_type); > my $cache = $subclass->_cache_handle($param) > or croak "Cannot create cache handle for '$cache_type'"; > return bless $class->SUPER::new({cache => $cache}), $subclass; > } > >+sub is_cache_active { >+ warn "ENV CACHING = ".$ENV{CACHING_SYSTEM}; >+ return $ENV{CACHING_SYSTEM} ? '1' : '' ; >+} >+ > =head2 EXPORT > > None by default. >@@ -74,6 +79,7 @@ Koha::Cache::Memcached > =head1 AUTHOR > > Chris Cormack, E<lt>chris@bigballofwax.co.nzE<gt> >+Paul Poulain, E<lt>paul.poulain@biblibre.comE<gt> > > =cut > >diff --git a/Koha/Cache/Memcached.pm b/Koha/Cache/Memcached.pm >index 87fe3c7..d8b7ad2 100644 >--- a/Koha/Cache/Memcached.pm >+++ b/Koha/Cache/Memcached.pm >@@ -28,7 +28,7 @@ use base qw(Koha::Cache); > sub _cache_handle { > my $class = shift; > my $params = shift; >- my @servers = split /,/, $params->{'cache_servers'}; >+ my @servers = split /,/, $params->{'cache_servers'}?$params->{'cache_servers'}:$ENV{MEMCACHED_SERVERS}; > return Cache::Memcached->new( > servers => \@servers, > namespace => $params->{'namespace'} || 'KOHA', >@@ -39,7 +39,8 @@ sub set_in_cache { > my ( $self, $key, $value, $expiry ) = @_; > croak "No key" unless $key; > $self->cache->set_debug; >- >+ $ENV{DEBUG} && warn "set_in_cache for Memcache $key"; >+ > if ( defined $expiry ) { > return $self->cache->set( $key, $value, $expiry ); > } >@@ -51,6 +52,7 @@ sub set_in_cache { > sub get_from_cache { > my ( $self, $key ) = @_; > croak "No key" unless $key; >+ $ENV{DEBUG} && warn "get_from_cache for Memcache $key"; > return $self->cache->get($key); > } > >diff --git a/opac/svc/report b/opac/svc/report >index 4fd8183..8781369 100755 >--- a/opac/svc/report >+++ b/opac/svc/report >@@ -25,27 +25,21 @@ use C4::Reports::Guided; > use JSON; > use CGI; > >+use Koha::Cache; >+ > my $query = CGI->new(); > my $report = $query->param('id'); > > my $cache; >-my $usecache = C4::Context->ismemcached; > > my ( $sql, $type, $name, $notes, $cache_expiry, $public ) = > get_saved_report($report); > die "Sorry this report is not public\n" unless $public; > >-if ($usecache) { >- require Koha::Cache; >- Koha::Cache->import(); >+if (Koha::Cache->is_cache_active) { > $cache = Koha::Cache->new( >- { >- 'cache_type' => 'memcached', >- 'cache_servers' => $ENV{'MEMCACHED_SERVERS'} >- } > ); >- my $namespace = $ENV{'MEMCACHED_NAMESPACE'} || 'koha'; >- my $page = $cache->get_from_cache("$namespace:opac:report:$report"); >+ my $page = $cache->get_from_cache("opac:report:$report"); > if ($page) { > print $query->header; > print $page; >@@ -61,8 +55,6 @@ my $lines = $sth->fetchall_arrayref; > my $json_text = to_json($lines); > print $json_text; > >-if ($usecache) { >- my $namespace = $ENV{'MEMCACHED_NAMESPACE'} || 'koha'; >- $cache->set_in_cache( "$namespace:opac:report:$report", >- $json_text, $cache_expiry ); >+if (Koha::Cache->is_cache_active) { >+ $cache->set_in_cache( "opac:report:$report", $json_text, $cache_expiry ); > } >diff --git a/svc/report b/svc/report >index 476475c..18e1986 100755 >--- a/svc/report >+++ b/svc/report >@@ -26,11 +26,13 @@ use C4::Reports::Guided; > use JSON; > use CGI; > >+use Koha::Cache; >+ >+ > my $query = CGI->new(); > my $report = $query->param('id'); > > my $cache; >-my $usecache = C4::Context->ismemcached; > > my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > { >@@ -42,17 +44,9 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > } > ); > >-if ($usecache) { >- require Koha::Cache; >- Koha::Cache->import(); >- $cache = Koha::Cache->new( >- { >- 'cache_type' => 'memcached', >- 'cache_servers' => $ENV{'MEMCACHED_SERVERS'} >- } >- ); >- my $namespace = $ENV{'MEMCACHED_NAMESPACE'} || 'koha'; >- my $page = $cache->get_from_cache("$namespace:intranet:report:$report"); >+if (Koha::Cache->is_cache_active) { >+ $cache = Koha::Cache->new(); >+ my $page = $cache->get_from_cache("intranet:report:$report"); > if ($page) { > print $query->header; > print $page; >@@ -72,8 +66,6 @@ my $lines = $sth->fetchall_arrayref; > my $json_text = to_json($lines); > print $json_text; > >-if ($usecache) { >- my $namespace = $ENV{'MEMCACHED_NAMESPACE'} || 'koha'; >- $cache->set_in_cache( "$namespace:intranet:report:$report", >- $json_text, $cache_expiry ); >+if (Koha::Cache->is_cache_active) { >+ $cache->set_in_cache( "intranet:report:$report", $json_text, $cache_expiry ); > } >-- >1.7.9.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 7248
:
6353
|
6354
|
6356
|
6359
|
6372
|
6771
|
6772
|
7342
|
7343
|
7366
|
7367
|
9348
|
9349
|
9352
|
9353
|
9360
|
9552
|
9553
|
9554
|
9555
|
9556
|
9567
|
9568
|
9569
|
9571