Bugzilla – Attachment 9555 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 (2) Adapting subs using Cache to new Caching API
Bug-7248-follow-up-2-Adapting-subs-using-Cache-to-.patch (text/plain), 4.89 KB, created by
Paul Poulain
on 2012-05-14 11:29:03 UTC
(
hide
)
Description:
Bug 7248 follow-up (2) Adapting subs using Cache to new Caching API
Filename:
MIME Type:
Creator:
Paul Poulain
Created:
2012-05-14 11:29:03 UTC
Size:
4.89 KB
patch
obsolete
>From e1dd15dfe35272529e07681dc5f7881ebe0f4aaf Mon Sep 17 00:00:00 2001 >From: Paul Poulain <paul.poulain@biblibre.com> >Date: Mon, 14 May 2012 13:27:29 +0200 >Subject: [PATCH] Bug 7248 follow-up (2) Adapting subs using Cache to new > Caching API > >guided_reports, Languages and Biblio::GetMarcStructure where the only subs that used caching > >This patch switches to the generic Koha::Cache namespace > >Test plan : >* have DEBUG env set to 1 >* reach addbiblio page to test the patch in Biblio.pm, or setup more than 1 language >* you should see in the logs that you're reading and writing from cache >--- > C4/Biblio.pm | 24 ++++++++---------------- > C4/Languages.pm | 32 +++++++++++++++++++++----------- > reports/guided_reports.pl | 3 ++- > 3 files changed, 31 insertions(+), 28 deletions(-) > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index 56cd94e..12a28a9 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -136,16 +136,6 @@ BEGIN { > ); > } > >-eval { >- if (C4::Context->ismemcached) { >- require Memoize::Memcached; >- import Memoize::Memcached qw(memoize_memcached); >- >- memoize_memcached( 'GetMarcStructure', >- memcached => C4::Context->memcached); >- } >-}; >- > =head1 NAME > > C4::Biblio - cataloging management functions >@@ -1058,12 +1048,11 @@ sub GetMarcStructure { > if ( defined $marc_structure_cache and exists $marc_structure_cache->{$forlibrarian}->{$frameworkcode} ) { > return $marc_structure_cache->{$forlibrarian}->{$frameworkcode}; > } >- >- # my $sth = $dbh->prepare( >- # "SELECT COUNT(*) FROM marc_tag_structure WHERE frameworkcode=?"); >- # $sth->execute($frameworkcode); >- # my ($total) = $sth->fetchrow; >- # $frameworkcode = "" unless ( $total > 0 ); >+ my $cache = Koha::Cache->new(); >+ if ($cache) { >+ my $cached = $cache->get_from_cache("GetMarcStructure:$frameworkcode:$forlibrarian"); >+ return $cached if $cached; >+ } > my $sth = $dbh->prepare( > "SELECT tagfield,liblibrarian,libopac,mandatory,repeatable > FROM marc_tag_structure >@@ -1127,6 +1116,9 @@ sub GetMarcStructure { > > $marc_structure_cache->{$forlibrarian}->{$frameworkcode} = $res; > >+ if ($cache) { >+ $cache->set_in_cache("GetMarcStructure:$frameworkcode:$forlibrarian",$res,10000); >+ } > return $res; > } > >diff --git a/C4/Languages.pm b/C4/Languages.pm >index 6f269ac..123f1bb 100644 >--- a/C4/Languages.pm >+++ b/C4/Languages.pm >@@ -23,19 +23,9 @@ use strict; > #use warnings; FIXME - Bug 2505 > use Carp; > use C4::Context; >+use Koha::Cache; > use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG); > >-eval { >- if (C4::Context->ismemcached) { >- require Memoize::Memcached; >- import Memoize::Memcached qw(memoize_memcached); >- >- memoize_memcached('getTranslatedLanguages', memcached => C4::Context->memcached); >- memoize_memcached('getFrameworkLanguages' , memcached => C4::Context->memcached); >- memoize_memcached('getAllLanguages', memcached => C4::Context->memcached); >- } >-}; >- > BEGIN { > $VERSION = 3.00; > require Exporter; >@@ -77,6 +67,12 @@ Returns a reference to an array of hashes: > =cut > > sub getFrameworkLanguages { >+ >+ my $cache = Koha::Cache->new(); >+ if ($cache) { >+ my $cached = $cache->get_from_cache("getFrameworkLanguages"); >+ return $cached if $cached; >+ } > # get a hash with all language codes, names, and locale names > my $all_languages = getAllLanguages(); > my @languages; >@@ -99,6 +95,9 @@ sub getFrameworkLanguages { > } > } > } >+ if ($cache) { >+ $cache->set_in_cache("getFrameworkLanguages",\@languages,10000) >+ } > return \@languages; > } > >@@ -179,6 +178,14 @@ Returns a reference to an array of hashes: > =cut > > sub getAllLanguages { >+ # retrieve from cache if applicable >+ my $cache = Koha::Cache->new(); >+ if ($cache) { >+ my $cached = $cache->get_from_cache("getAllLanguages"); >+ if ($cached) { >+ return $cached; >+ } >+ } > my @languages_loop; > my $dbh=C4::Context->dbh; > my $current_language = shift || 'en'; >@@ -213,6 +220,9 @@ sub getAllLanguages { > } > push @languages_loop, $language_subtag_registry; > } >+ if ($cache) { >+ $cache->set_in_cache("getAllLanguages",\@languages_loop,1000); >+ } > return \@languages_loop; > } > >diff --git a/reports/guided_reports.pl b/reports/guided_reports.pl >index fa4fc94..2db86b9 100755 >--- a/reports/guided_reports.pl >+++ b/reports/guided_reports.pl >@@ -28,6 +28,7 @@ use C4::Output; > use C4::Dates; > use C4::Debug; > use C4::Branch; # XXX subfield_is_koha_internal_p >+use Koha::Cache; > > =head1 NAME > >@@ -40,7 +41,7 @@ Script to control the guided report creation > =cut > > my $input = new CGI; >-my $usecache = C4::Context->ismemcached; >+my $usecache = Koha::Cache->new()?1:0; > > my $phase = $input->param('phase'); > my $flagsrequired; >-- >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