Bug 11842 - fix framework caching with memcache/plack
This changes the existing framework caching, which was using memoisation if memcached was available, and memory in all cases, to use the Koha::Cache system. This uses memcache if possible, and in-memory otherwise. However it also clears the cache when the framework updates, making sure that the changed version will be picked up. Note that the in-memory cache clears itself after 10 seconds, so that if memcached isn't available, this is the longest that old versions will hang around. Test plan: * work through http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=11842#c0 and make sure that the erronious result doesn't occur. Note: * The patch on bug 12041 is required for this to work. Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com> Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
This commit is contained in:
parent
4107444c03
commit
71ba269136
32
C4/Biblio.pm
32
C4/Biblio.pm
|
|
@ -39,6 +39,8 @@ use C4::Charset;
|
|||
use C4::Linker;
|
||||
use C4::OAI::Sets;
|
||||
|
||||
use Koha::Cache;
|
||||
|
||||
use vars qw($VERSION @ISA @EXPORT);
|
||||
|
||||
BEGIN {
|
||||
|
|
@ -139,16 +141,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
|
||||
|
|
@ -1099,24 +1091,17 @@ $frameworkcode : the framework code to read
|
|||
|
||||
=cut
|
||||
|
||||
# cache for results of GetMarcStructure -- needed
|
||||
# for batch jobs
|
||||
our $marc_structure_cache;
|
||||
|
||||
sub GetMarcStructure {
|
||||
my ( $forlibrarian, $frameworkcode ) = @_;
|
||||
my $dbh = C4::Context->dbh;
|
||||
$frameworkcode = "" unless $frameworkcode;
|
||||
|
||||
if ( defined $marc_structure_cache and exists $marc_structure_cache->{$forlibrarian}->{$frameworkcode} ) {
|
||||
return $marc_structure_cache->{$forlibrarian}->{$frameworkcode};
|
||||
}
|
||||
$forlibrarian = $forlibrarian ? 1 : 0;
|
||||
my $cache = Koha::Cache->get_instance();
|
||||
my $cache_key = "MarcStructure-$forlibrarian-$frameworkcode";
|
||||
my $cached = $cache->get_from_cache($cache_key);
|
||||
return $cached if $cached;
|
||||
|
||||
# my $sth = $dbh->prepare(
|
||||
# "SELECT COUNT(*) FROM marc_tag_structure WHERE frameworkcode=?");
|
||||
# $sth->execute($frameworkcode);
|
||||
# my ($total) = $sth->fetchrow;
|
||||
# $frameworkcode = "" unless ( $total > 0 );
|
||||
my $sth = $dbh->prepare(
|
||||
"SELECT tagfield,liblibrarian,libopac,mandatory,repeatable
|
||||
FROM marc_tag_structure
|
||||
|
|
@ -1178,8 +1163,7 @@ sub GetMarcStructure {
|
|||
$res->{$tag}->{$subfield}->{maxlength} = $maxlength;
|
||||
}
|
||||
|
||||
$marc_structure_cache->{$forlibrarian}->{$frameworkcode} = $res;
|
||||
|
||||
$cache->set_in_cache($cache_key, $res);
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ use CGI;
|
|||
use C4::Context;
|
||||
use C4::Auth;
|
||||
use C4::Output;
|
||||
use Koha::Cache;
|
||||
|
||||
sub StringSearch {
|
||||
my $dbh = C4::Context->dbh;
|
||||
|
|
@ -41,6 +42,7 @@ my $frameworkcode = $input->param('frameworkcode') || '';
|
|||
my $offset = $input->param('offset') || 0;
|
||||
my $op = $input->param('op') || '';
|
||||
my $pagesize = 20;
|
||||
my $cache = Koha::Cache->get_instance();
|
||||
|
||||
my ($template, $borrowernumber, $cookie)
|
||||
= get_template_and_user({template_name => "admin/biblio_framework.tt",
|
||||
|
|
@ -74,15 +76,17 @@ if ($op eq 'add_form') {
|
|||
################## ADD_VALIDATE ##################################
|
||||
# called by add_form, used to insert/modify data in DB
|
||||
} elsif ($op eq 'add_validate') {
|
||||
my $dbh = C4::Context->dbh;
|
||||
if($input->param('frameworktext') and $input->param('frameworkcode')){
|
||||
my $dbh = C4::Context->dbh;
|
||||
if ( $input->param('frameworktext') and $frameworkcode ) {
|
||||
if ($input->param('modif')) {
|
||||
my $sth=$dbh->prepare("UPDATE biblio_framework SET frameworktext=? WHERE frameworkcode=?");
|
||||
$sth->execute($input->param('frameworktext'),$input->param('frameworkcode'));
|
||||
$sth->execute( $input->param('frameworktext'), $frameworkcode );
|
||||
} else {
|
||||
my $sth=$dbh->prepare("INSERT into biblio_framework (frameworkcode,frameworktext) values (?,?)");
|
||||
$sth->execute($input->param('frameworkcode'),$input->param('frameworktext'));
|
||||
$sth->execute( $frameworkcode, $input->param('frameworktext') );
|
||||
}
|
||||
$cache->clear_from_cache("MarcStructure-0-$frameworkcode");
|
||||
$cache->clear_from_cache("MarcStructure-1-$frameworkcode");
|
||||
}
|
||||
print $input->redirect($script_name); # FIXME: unnecessary redirect
|
||||
exit;
|
||||
|
|
@ -115,6 +119,8 @@ if ($op eq 'add_form') {
|
|||
$sth->execute($frameworkcode);
|
||||
$sth=$dbh->prepare("delete from biblio_framework where frameworkcode=?");
|
||||
$sth->execute($frameworkcode);
|
||||
$cache->clear_from_cache("MarcStructure-0-$frameworkcode");
|
||||
$cache->clear_from_cache("MarcStructure-1-$frameworkcode");
|
||||
}
|
||||
print $input->redirect($script_name); # FIXME: unnecessary redirect
|
||||
exit;
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ else {
|
|||
}
|
||||
|
||||
my $dbh = C4::Context->dbh;
|
||||
my $cache = Koha::Cache->get_instance();
|
||||
|
||||
################## ADD_FORM ##################################
|
||||
# called by default. Used to create form to add or modify a record
|
||||
|
|
@ -112,6 +113,9 @@ elsif ( $op eq 'add_validate' ) {
|
|||
$dbh->do(
|
||||
"update marc_subfield_structure set kohafield='$tablename.$kohafield' where tagfield='$temp[0]' and tagsubfield='$temp[1]'"
|
||||
);
|
||||
# We could get a list of all frameworks and do them one-by-one, or zap
|
||||
# everything.
|
||||
$cache->flush_all();
|
||||
print
|
||||
"Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=koha2marclinks.pl?tablename=$tablename\"></html>";
|
||||
exit;
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
|
|||
debug => 1,
|
||||
}
|
||||
);
|
||||
my $cache = Koha::Cache->get_instance();
|
||||
|
||||
my $op = $input->param('op');
|
||||
$tagfield =~ s/\,//g;
|
||||
|
|
@ -424,6 +425,9 @@ elsif ( $op eq 'add_validate' ) {
|
|||
}
|
||||
$sth_insert->finish;
|
||||
$sth_update->finish;
|
||||
$cache->clear_from_cache("MarcStructure-0-$frameworkcode");
|
||||
$cache->clear_from_cache("MarcStructure-1-$frameworkcode");
|
||||
|
||||
print
|
||||
"Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=marc_subfields_structure.pl?tagfield=$tagfield&frameworkcode=$frameworkcode\"></html>";
|
||||
exit;
|
||||
|
|
@ -465,6 +469,8 @@ elsif ( $op eq 'delete_confirmed' ) {
|
|||
$sth->execute( $tagfield, $tagsubfield, $frameworkcode );
|
||||
$sth->finish;
|
||||
}
|
||||
$cache->clear_from_cache("MarcStructure-0-$frameworkcode");
|
||||
$cache->clear_from_cache("MarcStructure-1-$frameworkcode");
|
||||
print
|
||||
"Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=marc_subfields_structure.pl?tagfield=$tagfield&frameworkcode=$frameworkcode\"></html>";
|
||||
exit;
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ use C4::Context;
|
|||
use C4::Output;
|
||||
use C4::Context;
|
||||
|
||||
use Koha::Cache;
|
||||
|
||||
# retrieve parameters
|
||||
my $input = new CGI;
|
||||
|
|
@ -45,6 +46,7 @@ my $pagesize = 20;
|
|||
my $script_name = "/cgi-bin/koha/admin/marctagstructure.pl";
|
||||
|
||||
my $dbh = C4::Context->dbh;
|
||||
my $cache = Koha::Cache->get_instance();
|
||||
|
||||
# open template
|
||||
my ($template, $loggedinuser, $cookie)
|
||||
|
|
@ -160,6 +162,8 @@ if ($op eq 'add_form') {
|
|||
$frameworkcode
|
||||
);
|
||||
}
|
||||
$cache->clear_from_cache("MarcStructure-0-$frameworkcode");
|
||||
$cache->clear_from_cache("MarcStructure-1-$frameworkcode");
|
||||
}
|
||||
print $input->redirect("/cgi-bin/koha/admin/marctagstructure.pl?searchfield=$tagfield&frameworkcode=$frameworkcode");
|
||||
exit;
|
||||
|
|
@ -184,6 +188,8 @@ if ($op eq 'add_form') {
|
|||
my $sth2 = $dbh->prepare("DELETE FROM marc_subfield_structure WHERE tagfield=? AND frameworkcode=?");
|
||||
$sth1->execute($searchfield, $frameworkcode);
|
||||
$sth2->execute($searchfield, $frameworkcode);
|
||||
$cache->clear_from_cache("MarcStructure-0-$frameworkcode");
|
||||
$cache->clear_from_cache("MarcStructure-1-$frameworkcode");
|
||||
}
|
||||
$template->param(
|
||||
searchfield => $searchfield,
|
||||
|
|
@ -347,5 +353,7 @@ sub duplicate_framework {
|
|||
while ( my ($frameworkcode, $tagfield, $tagsubfield, $liblibrarian, $libopac, $repeatable, $mandatory, $kohafield, $tab, $authorised_value, $thesaurus_category, $value_builder, $seealso,$hidden) = $sth->fetchrow) {
|
||||
$sth_insert->execute($newframeworkcode, $tagfield, $tagsubfield, $liblibrarian, $libopac, $repeatable, $mandatory, $kohafield, $tab, $authorised_value, $thesaurus_category, $value_builder, $seealso, $hidden);
|
||||
}
|
||||
$cache->clear_from_cache("MarcStructure-0-$newframeworkcode");
|
||||
$cache->clear_from_cache("MarcStructure-1-$newframeworkcode");
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue