Bugzilla – Attachment 9552 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/7249 follow-up: more generic cache handling
Bug-72487249-follow-up-more-generic-cache-handling.patch (text/plain), 5.98 KB, created by
Paul Poulain
on 2012-05-14 09:29:42 UTC
(
hide
)
Description:
Bug 7248/7249 follow-up: more generic cache handling
Filename:
MIME Type:
Creator:
Paul Poulain
Created:
2012-05-14 09:29:42 UTC
Size:
5.98 KB
patch
obsolete
>From 6662de0978cbcdd89691b319895a6201930d2e40 Mon Sep 17 00:00:00 2001 >From: Paul Poulain <paul.poulain@biblibre.com> >Date: Mon, 14 May 2012 11:29:19 +0200 >Subject: [PATCH] Bug 7248/7249 follow-up: more generic cache handling > >This patch update the cache handling to Koha::Cache. So, whatever the cache mechanism is, Koha caching will work this way: > >use Koha::Cache; >my $cache = Koha::Cache->new(); > >if ($cache) { > $cache->get_from_cache($identifier) >} >if ($cache) { >$cache->set_in_cache( $identifier, > $value, $cache_expiry ); >} > >Test plan: > * setup a Koha with MEMCACHE activated (MEMCACHED_NAMESPACE is defined in koha-httpd.conf) > * setup Koha with DEBUG on (SetEnv DEBUG "1" in koha-httpd.conf) > * restart Apache > * load a report $KOHA/cgi-bin/koha/svc/report?id=<ID> > >In the Apache logs you will get: >* report: We have and will use a cache at /home/paul/koha.dev/koha-community/opac/svc/report line 40. > => confirmation we will use memcache >* execute_query(<A QUERY>) > => the cache is still empty, we run the SQL > >load the report again, you'll get: >* report: We have and will use a cache at /home/paul/koha.dev/koha-community/opac/svc/report line 40. > => confirmation we will use memcache >* report: Report <ID> retrieved from cache at /home/paul/koha.dev/koha-community/opac/svc/report line 43. > => confirmation we are retrieving the result from the cache > >Remove the MEMCACHE env variable, restart Apache, reload the page, you'll get: >* report: No caching system at /home/paul/koha.dev/koha-community/Koha/Cache.pm line 75. >=> confirmation you have no caching system active >--- > Koha/Cache.pm | 25 +++++++++++++++++++------ > opac/svc/report | 25 +++++++++---------------- > svc/report | 23 +++++++---------------- > 3 files changed, 35 insertions(+), 38 deletions(-) > >diff --git a/Koha/Cache.pm b/Koha/Cache.pm >index 25aad93..ca409b7 100644 >--- a/Koha/Cache.pm >+++ b/Koha/Cache.pm >@@ -55,12 +55,25 @@ __PACKAGE__->mk_ro_accessors( qw( cache ) ); > > sub new { > 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) >- or croak "Cannot create cache handle for '$cache_type'"; >- return bless $class->SUPER::new({cache => $cache}), $subclass; >+# my $param = shift; >+ my $cache; >+ my $subclass; >+ # try to find which cache type we use >+ if ($ENV{'MEMCACHED_SERVERS'}) { >+ # we use MEMCACHE >+ $subclass = __PACKAGE__."::Memcached"; >+ $cache = $subclass->_cache_handle( >+ {'cache_type' => 'memcached', >+ 'cache_servers' => $ENV{'MEMCACHED_SERVERS'}, >+ 'namespace' => $ENV{'MEMCACHED_NAMESPACE'}, >+ } >+ ) >+ or croak "Cannot create cache handle for memcache"; >+ return bless $class->SUPER::new({cache => $cache}), $subclass; >+ } else { >+ $ENV{DEBUG} && warn "No caching system"; >+ return; >+ } > } > > =head2 EXPORT >diff --git a/opac/svc/report b/opac/svc/report >index 4fd8183..2df20bc 100755 >--- a/opac/svc/report >+++ b/opac/svc/report >@@ -28,25 +28,19 @@ use CGI; > my $query = CGI->new(); > my $report = $query->param('id'); > >-my $cache; >-my $usecache = C4::Context->ismemcached; >+# load caching. If we have one, then we will try to retrieve the report from the cache for better performances >+use Koha::Cache; >+my $cache = Koha::Cache->new(); > > 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(); >- $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"); >+if ($cache) { >+ $ENV{DEBUG} && warn "We have and will use a cache"; >+ my $page = $cache->get_from_cache("opac:report:$report"); > if ($page) { >+ $ENV{DEBUG} && warn "Report $report retrieved from cache"; > print $query->header; > print $page; > exit; >@@ -61,8 +55,7 @@ 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", >+if ($cache) { >+ $cache->set_in_cache( "opac:report:$report", > $json_text, $cache_expiry ); > } >diff --git a/svc/report b/svc/report >index 476475c..0764e2d 100755 >--- a/svc/report >+++ b/svc/report >@@ -29,8 +29,9 @@ use CGI; > my $query = CGI->new(); > my $report = $query->param('id'); > >-my $cache; >-my $usecache = C4::Context->ismemcached; >+# load caching. If we have one, then we will try to retrieve the report from the cache for better performances >+use Koha::Cache; >+my $cache = Koha::Cache->new(); > > my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > { >@@ -42,17 +43,8 @@ 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 ($cache) { >+ my $page = $cache->get_from_cache("intranet:report:$report"); > if ($page) { > print $query->header; > print $page; >@@ -72,8 +64,7 @@ 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", >+if ($cache) { >+ $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