Bugzilla – Attachment 55578 Details for
Bug 15562
Make Koha more suitable for shared hosting with plack
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
bug_15562: Removed Koha::Caches->get_instance()
bug15562-Removed-KohaCaches-getinstance.patch (text/plain), 32.25 KB, created by
Srdjan Jankovic
on 2016-09-15 06:27:45 UTC
(
hide
)
Description:
bug_15562: Removed Koha::Caches->get_instance()
Filename:
MIME Type:
Creator:
Srdjan Jankovic
Created:
2016-09-15 06:27:45 UTC
Size:
32.25 KB
patch
obsolete
>From 1e6b593314a052440919779faa91409b4915bb7c Mon Sep 17 00:00:00 2001 >From: Srdjan <srdjan@catalyst.net.nz> >Date: Wed, 27 Jan 2016 16:57:18 +1300 >Subject: [PATCH] bug_15562: Removed Koha::Caches->get_instance() > >There should be no cache singletons, full stop. If Koha is to move away >from .pl scripts that is. >As an interim measure Koha::Caches->get_instance() is replaced with >C4::Context->cache. In that respect it will continue to work in the >singleton-ish way if context is used as a singleton, but supports cache-per-context. > >Koha::Handler::Plack->app_per_host() cache sysprefs using Context memcached. > >https://bugs.koha-community.org/show_bug.cgi?id=15562 >--- > C4/Auth.pm | 10 +++--- > C4/Biblio.pm | 6 ++-- > C4/Calendar.pm | 15 +++++---- > C4/Context.pm | 54 ++++++++++++++++++++++++--------- > C4/External/OverDrive.pm | 6 ++-- > C4/Items.pm | 2 +- > C4/Koha.pm | 3 +- > C4/Utils/DataTables/ColumnsSettings.pm | 3 +- > Koha/Cache.pm | 43 +++++++++++--------------- > Koha/Caches.pm | 10 +++--- > Koha/Calendar.pm | 5 ++- > Koha/Handler/Plack.pm | 41 +++++++++++++++++++++++-- > Koha/Handler/Plack/CGI.pm | 2 +- > Koha/MetaSearcher.pm | 4 +-- > Koha/Template/Plugin/Cache.pm | 4 +-- > admin/biblio_framework.pl | 3 +- > admin/koha2marclinks.pl | 2 +- > admin/marc_subfields_structure.pl | 2 +- > admin/marctagstructure.pl | 5 +-- > opac/svc/report | 5 ++- > reports/guided_reports.pl | 3 +- > svc/report | 4 +-- > t/Calendar.t | 4 +-- > t/Context.t | 28 ++++++++++++++++- > t/Koha_Template_Plugin_Cache.t | 4 ++- > t/db_dependent/Context.t | 8 +---- > t/db_dependent/Filter_MARC_ViewPolicy.t | 5 ++- > t/db_dependent/Items.t | 5 +-- > tools/newHolidays.pl | 4 +-- > 29 files changed, 176 insertions(+), 114 deletions(-) > >diff --git a/C4/Auth.pm b/C4/Auth.pm >index 6b7dc66..d43a3e3 100644 >--- a/C4/Auth.pm >+++ b/C4/Auth.pm >@@ -31,7 +31,6 @@ use C4::Templates; # to get the template > use C4::Languages; > use C4::Search::History; > use Koha; >-use Koha::Caches; > use Koha::AuthUtils qw(get_script_name hash_password); > use Koha::Libraries; > use Koha::LibraryCategories; >@@ -1733,11 +1732,12 @@ sub get_session { > elsif ( $storage_method eq 'Pg' ) { > $session = new CGI::Session( "driver:PostgreSQL;serializer:yaml;id:md5", $sessionID, { Handle => $dbh } ); > } >- elsif ( $storage_method eq 'memcached' && Koha::Caches->get_instance->memcached_cache ) { >- my $memcached = Koha::Caches->get_instance()->memcached_cache; >- $session = new CGI::Session( "driver:memcached;serializer:yaml;id:md5", $sessionID, { Memcached => $memcached } ); >+ elsif ( $storage_method eq 'memcached' ) { >+ if ( my $memcached = C4::Context->cache->memcached_cache ) { >+ $session = new CGI::Session( "driver:memcached;serializer:yaml;id:md5", $sessionID, { Memcached => $memcached } ); >+ } > } >- else { >+ unless ($session) { > # catch all defaults to tmp should work on all systems > my $dir = File::Spec->tmpdir; > my $instance = C4::Context->config( 'database' ); #actually for packages not exactly the instance name, but generally safer to leave it as it is >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index a1f70b8..4c54bb8 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -37,8 +37,8 @@ use C4::Charset; > use C4::Linker; > use C4::OAI::Sets; > use C4::Debug; >+use C4::Context; > >-use Koha::Caches; > use Koha::Authority::Types; > use Koha::Acquisition::Currencies; > use Koha::SearchEngine; >@@ -1136,7 +1136,7 @@ sub GetMarcStructure { > > $forlibrarian = $forlibrarian ? 1 : 0; > my $unsafe = ($params && $params->{unsafe})? 1: 0; >- my $cache = Koha::Caches->get_instance(); >+ my $cache = C4::Context->cache; > my $cache_key = "MarcStructure-$forlibrarian-$frameworkcode"; > my $cached = $cache->get_from_cache($cache_key, { unsafe => $unsafe }); > return $cached if $cached; >@@ -1244,7 +1244,7 @@ sub GetMarcSubfieldStructure { > > $frameworkcode //= ''; > >- my $cache = Koha::Caches->get_instance(); >+ my $cache = C4::Context->cache; > my $cache_key = "MarcSubfieldStructure-$frameworkcode"; > my $cached = $cache->get_from_cache($cache_key); > return $cached if $cached; >diff --git a/C4/Calendar.pm b/C4/Calendar.pm >index 2c1b0d8..3a38173 100644 >--- a/C4/Calendar.pm >+++ b/C4/Calendar.pm >@@ -23,7 +23,6 @@ use Carp; > use Date::Calc qw( Date_to_Days Today); > > use C4::Context; >-use Koha::Caches; > > use constant ISO_DATE_FORMAT => "%04d-%02d-%02d"; > >@@ -276,7 +275,7 @@ sub insert_single_holiday { > > > # changed the 'single_holidays' table, lets force/reset its cache >- my $cache = Koha::Caches->get_instance(); >+ my $cache = C4::Context->cache; > $cache->clear_from_cache( 'single_holidays') ; > $cache->clear_from_cache( 'exception_holidays') ; > >@@ -321,7 +320,7 @@ sub insert_exception_holiday { > $self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description}; > > # changed the 'single_holidays' table, lets force/reset its cache >- my $cache = Koha::Caches->get_instance(); >+ my $cache = C4::Context->cache; > $cache->clear_from_cache( 'single_holidays') ; > $cache->clear_from_cache( 'exception_holidays') ; > >@@ -422,7 +421,7 @@ UPDATE special_holidays SET title = ?, description = ? > $self->{'single_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description}; > > # changed the 'single_holidays' table, lets force/reset its cache >- my $cache = Koha::Caches->get_instance(); >+ my $cache = C4::Context->cache; > $cache->clear_from_cache( 'single_holidays') ; > $cache->clear_from_cache( 'exception_holidays') ; > >@@ -465,7 +464,7 @@ UPDATE special_holidays SET title = ?, description = ? > $self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description}; > > # changed the 'single_holidays' table, lets force/reset its cache >- my $cache = Koha::Caches->get_instance(); >+ my $cache = C4::Context->cache; > $cache->clear_from_cache( 'single_holidays') ; > $cache->clear_from_cache( 'exception_holidays') ; > >@@ -546,7 +545,7 @@ sub delete_holiday { > } > > # changed the 'single_holidays' table, lets force/reset its cache >- my $cache = Koha::Caches->get_instance(); >+ my $cache = C4::Context->cache; > $cache->clear_from_cache( 'single_holidays') ; > $cache->clear_from_cache( 'exception_holidays') ; > >@@ -577,7 +576,7 @@ sub delete_holiday_range { > $sth->execute($self->{branchcode}, $options{day}, $options{month}, $options{year}); > > # changed the 'single_holidays' table, lets force/reset its cache >- my $cache = Koha::Caches->get_instance(); >+ my $cache = C4::Context->cache; > $cache->clear_from_cache( 'single_holidays') ; > $cache->clear_from_cache( 'exception_holidays') ; > >@@ -631,7 +630,7 @@ sub delete_exception_holiday_range { > $sth->execute($self->{branchcode}, $options{day}, $options{month}, $options{year}); > > # changed the 'single_holidays' table, lets force/reset its cache >- my $cache = Koha::Caches->get_instance(); >+ my $cache = C4::Context->cache; > $cache->clear_from_cache( 'single_holidays') ; > $cache->clear_from_cache( 'exception_holidays') ; > } >diff --git a/C4/Context.pm b/C4/Context.pm >index b8f765d..3bf1c2f 100644 >--- a/C4/Context.pm >+++ b/C4/Context.pm >@@ -178,6 +178,33 @@ sub current { > return $context; > } > >+=head2 cache >+ >+Returns the cache object or undef >+ >+=cut >+ >+sub cache { >+ my $self = shift; >+ $self = $context unless ref ($self); >+ >+ return Koha::Caches->get_instance($self->{namespace}); >+} >+ >+=head2 memcached >+ >+Returns the cache object if it is memcached or undef >+ >+=cut >+ >+sub memcached { >+ my $self = shift; >+ my $cache = $self->cache; >+ return $cache if $cache->{memcached_cache}; >+ >+ return; >+} >+ > sub db_driver { > my $self = shift; > >@@ -220,11 +247,10 @@ sub import { > # multihost, we don't want/have one default config > return if $config_file && $config_file eq ":no_config"; > >- my $conf_cache = Koha::Caches->get_instance('config'); >- if ( $conf_cache->cache ) { >- if ( $context = $conf_cache->get_from_cache('koha_conf') ) { >- return; >- } >+ my $cache = Koha::Caches->get_instance(); >+ undef $cache unless $cache->{memcached_cache}; >+ if ( $cache and $context = $cache->get_from_cache('koha_conf') ) { >+ return; > } > > undef $config_file if $config_file && !-s $config_file; >@@ -232,10 +258,10 @@ sub import { > $context = __PACKAGE__->new($config_file); > return unless $context; > >- if ( $conf_cache->memcached_cache ) { >+ if ( $cache ) { > # FIXME it may be better to use the memcached servers from the config file > # to cache it >- $conf_cache->set_in_cache('koha_conf', $context) >+ $cache->set_in_cache('koha_conf', $context) > } > } > >@@ -266,7 +292,6 @@ sub new { > $self->{config_file} = $conf_fname; > $self->{namespace} = $namespace; > $self->{use_syspref_cache} = 1; >- $self->{syspref_cache} = Koha::Cache->new({namespace => $namespace}); > > $self->{"Zconn"} = undef; # Zebra Connections > $self->{"userenv"} = undef; # User env >@@ -446,7 +471,7 @@ sub preference { > if defined $ENV{"OVERRIDE_SYSPREF_$var"}; > > my $cached_var = $self->{use_syspref_cache} >- ? $self->{syspref_cache}->get_from_cache("syspref_$var") >+ ? $self->cache->get_from_cache("syspref_$var") > : undef; > return $cached_var if defined $cached_var; > >@@ -455,7 +480,8 @@ sub preference { > my $value = $syspref ? $syspref->value() : undef; > > if ( $self->{use_syspref_cache} ) { >- $self->{syspref_cache}->set_in_cache("syspref_$var", $value); >+ $self->cache->set_in_cache("syspref_$var", $value); >+ $self->{sysprefs}{$var} = $value if $self; > } > return $value; > } >@@ -496,8 +522,8 @@ used with Plack and other persistent environments. > sub disable_syspref_cache { > my ($self) = @_; > $self = $context unless ref $self; >- $self->{use_syspref_cache} = 0; > $self->clear_syspref_cache(); >+ $self->{use_syspref_cache} = 0; > } > > =head2 clear_syspref_cache >@@ -514,7 +540,7 @@ sub clear_syspref_cache { > my ($self) = @_; > $self = $context unless ref $self; > return unless $self->{use_syspref_cache}; >- $self->{syspref_cache}->flush_all; >+ $self->cache->flush_all; > } > > =head2 set_preference >@@ -567,7 +593,7 @@ sub set_preference { > } > > if ( $self->{use_syspref_cache} ) { >- $self->{syspref_cache}->set_in_cache( "syspref_$variable", $value ); >+ $self->cache->set_in_cache( "syspref_$variable", $value ); > } > > return $syspref; >@@ -589,7 +615,7 @@ sub delete_preference { > > if ( Koha::Config::SysPrefs->find( $var )->delete ) { > if ( $self->{use_syspref_cache} ) { >- $self->{syspref_cache}->clear_from_cache("syspref_$var"); >+ $self->cache->clear_from_cache("syspref_$var"); > } > > return 1; >diff --git a/C4/External/OverDrive.pm b/C4/External/OverDrive.pm >index 9044169..0e71707 100644 >--- a/C4/External/OverDrive.pm >+++ b/C4/External/OverDrive.pm >@@ -22,7 +22,7 @@ use warnings; > > use Koha; > use JSON; >-use Koha::Caches; >+use C4::Context; > use HTTP::Request; > use HTTP::Request::Common; > use LWP::Authen::Basic; >@@ -97,9 +97,7 @@ sub GetOverDriveToken { > > return unless ( $key && $secret ) ; > >- my $cache; >- >- eval { $cache = Koha::Caches->get_instance() }; >+ my $cache = C4::Context->cache; > > my $token; > $cache and $token = $cache->get_from_cache( "overdrive_token" ) and return $token; >diff --git a/C4/Items.pm b/C4/Items.pm >index 71b1619..8c66b19 100644 >--- a/C4/Items.pm >+++ b/C4/Items.pm >@@ -459,7 +459,7 @@ Returns item record > sub _build_default_values_for_mod_marc { > my ($frameworkcode) = @_; > >- my $cache = Koha::Caches->get_instance(); >+ my $cache = C4::Context->cache; > my $cache_key = "default_value_for_mod_marc-$frameworkcode"; > my $cached = $cache->get_from_cache($cache_key); > return $cached if $cached; >diff --git a/C4/Koha.pm b/C4/Koha.pm >index 0ff4851..9263f4a 100644 >--- a/C4/Koha.pm >+++ b/C4/Koha.pm >@@ -24,7 +24,6 @@ use strict; > #use warnings; FIXME - Bug 2505 > > use C4::Context; >-use Koha::Caches; > use Koha::DateUtils qw(dt_from_string); > use Koha::Libraries; > use DateTime::Format::MySQL; >@@ -942,7 +941,7 @@ sub GetAuthorisedValues { > C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; > my $cache_key = > "AuthorisedValues-$category-$opac-$branch_limit"; >- my $cache = Koha::Caches->get_instance(); >+ my $cache = C4::Context->cache; > my $result = $cache->get_from_cache($cache_key); > return $result if $result; > >diff --git a/C4/Utils/DataTables/ColumnsSettings.pm b/C4/Utils/DataTables/ColumnsSettings.pm >index 8713489..31068b4 100644 >--- a/C4/Utils/DataTables/ColumnsSettings.pm >+++ b/C4/Utils/DataTables/ColumnsSettings.pm >@@ -5,11 +5,10 @@ use List::Util qw( first ); > use YAML; > use C4::Context; > use Koha::Database; >-use Koha::Caches; > > sub get_yaml { > my $yml_path = C4::Context->config('intranetdir') . '/admin/columns_settings.yml'; >- my $cache = Koha::Caches->get_instance(); >+ my $cache = C4::Context->cache; > my $yaml = $cache->get_from_cache('ColumnsSettingsYaml'); > > unless ($yaml) { >diff --git a/Koha/Cache.pm b/Koha/Cache.pm >index 08577bd..3310ae3 100644 >--- a/Koha/Cache.pm >+++ b/Koha/Cache.pm >@@ -54,16 +54,6 @@ our %L1_cache; > our $L1_encoder = Sereal::Encoder->new; > our $L1_decoder = Sereal::Decoder->new; > >-=head2 get_instance >- >- my $cache = Koha::Caches->get_instance(); >- >-This gets a shared instance of the cache, set up in a very default way. This is >-the recommended way to fetch a cache object. If possible, it'll be >-persistent across multiple instances. >- >-=cut >- > =head2 new > > Create a new Koha::Cache object. This is required for all cache-related functionality. >@@ -71,34 +61,35 @@ Create a new Koha::Cache object. This is required for all cache-related function > =cut > > sub new { >- my ( $class, $self, $params ) = @_; >+ my ( $class, $self ) = @_; > $self->{'default_type'} = > $self->{cache_type} > || $ENV{CACHING_SYSTEM} # DELME What about this? > || 'memcached'; > >- my $subnamespace = $params->{subnamespace} // ''; >+ $self->{namespace} //= ''; > > $ENV{DEBUG} && carp "Default caching system: $self->{'default_type'}"; > > $self->{'timeout'} ||= 0; >- # Should we continue to support MEMCACHED ENV vars? >- $self->{'namespace'} ||= $ENV{MEMCACHED_NAMESPACE}; >- my @servers = split /,/, $ENV{MEMCACHED_SERVERS} || ''; >- unless ( $self->{namespace} and @servers ) { >- my $koha_config = Koha::Config->read_from_file( Koha::Config->guess_koha_conf() ); >- $self->{namespace} ||= $koha_config->{config}{memcached_namespace} || 'koha'; >- @servers = split /,/, $koha_config->{config}{memcached_servers} // '' >- unless @servers; >- } >- $self->{namespace} .= ":$subnamespace:"; > > if ( $self->{'default_type'} eq 'memcached' >- && can_load( modules => { 'Cache::Memcached::Fast' => undef } ) >- && _initialize_memcached($self, @servers) >- && defined( $self->{'memcached_cache'} ) ) >+ && can_load( modules => { 'Cache::Memcached::Fast' => undef } ) ) > { >- $self->{'cache'} = $self->{'memcached_cache'}; >+ # Should we continue to support MEMCACHED ENV vars? >+ $self->{'namespace'} ||= $ENV{MEMCACHED_NAMESPACE}; >+ my @servers = split /,/, $ENV{MEMCACHED_SERVERS} || ''; >+ unless ( $self->{namespace} && @servers ) { >+ my $koha_config = Koha::Config->read_from_file( Koha::Config->guess_koha_conf() ); >+ $self->{namespace} ||= $koha_config->{config}{memcached_namespace} || 'koha'; >+ @servers = split /,/, $koha_config->{config}{memcached_servers} // '' >+ unless @servers; >+ } >+ if ( _initialize_memcached($self, @servers) >+ && defined( $self->{'memcached_cache'} ) ) >+ { >+ $self->{'cache'} = $self->{'memcached_cache'}; >+ } > } > > if ( $self->{'default_type'} eq 'fastmmap' >diff --git a/Koha/Caches.pm b/Koha/Caches.pm >index 52f1812..c5df4ec 100644 >--- a/Koha/Caches.pm >+++ b/Koha/Caches.pm >@@ -21,11 +21,11 @@ use Koha::Cache; > > our $singleton_caches; > sub get_instance { >- my ($class, $subnamespace) = @_; >- $subnamespace //= ''; >- $singleton_caches->{$subnamespace} = Koha::Cache->new({}, { subnamespace => $subnamespace } ) >- unless $singleton_caches->{$subnamespace}; >- return $singleton_caches->{$subnamespace}; >+ my ($class, $namespace) = @_; >+ $namespace //= ''; >+ $singleton_caches->{$namespace} = Koha::Cache->new({ namespace => $namespace } ) >+ unless $singleton_caches->{$namespace}; >+ return $singleton_caches->{$namespace}; > } > > sub flush_L1_caches { >diff --git a/Koha/Calendar.pm b/Koha/Calendar.pm >index 0065044..ada63ee 100644 >--- a/Koha/Calendar.pm >+++ b/Koha/Calendar.pm >@@ -7,7 +7,6 @@ use DateTime; > use DateTime::Set; > use DateTime::Duration; > use C4::Context; >-use Koha::Caches; > use Carp; > > sub new { >@@ -55,7 +54,7 @@ sub _init { > sub exception_holidays { > my ( $self ) = @_; > >- my $cache = Koha::Caches->get_instance(); >+ my $cache = C4::Context->cache; > my $cached = $cache->get_from_cache('exception_holidays'); > return $cached if $cached; > >@@ -84,7 +83,7 @@ sub exception_holidays { > sub single_holidays { > my ( $self, $date ) = @_; > my $branchcode = $self->{branchcode}; >- my $cache = Koha::Caches->get_instance(); >+ my $cache = C4::Context->cache; > my $single_holidays = $cache->get_from_cache('single_holidays'); > > # $single_holidays looks like: >diff --git a/Koha/Handler/Plack.pm b/Koha/Handler/Plack.pm >index af3f6cb..3760679 100644 >--- a/Koha/Handler/Plack.pm >+++ b/Koha/Handler/Plack.pm >@@ -69,6 +69,7 @@ use Plack::App::URLMap; > hostname => 'koha1.com', > app => $app1, > context => $context1, >+ shared_context => 1 > }, > { > hostname => ['koha2.com', 'www.koha2.com'], >@@ -78,13 +79,16 @@ use Plack::App::URLMap; > ... > > C<hostname> is mandatory. >+ If C<shared_context> is set to true, some Context properties will be preserved across >+ forked processes. Useful if both OPAC and Intranet apps are served here, so no restart >+ is needed when Context cached properties cnamge values. Needs memcached. > > koha.psgi: > > use Plack::Builder; > use Plack::App::CGIBin; > >- use C4::Context; >+ use C4::Context ":no_config"; > > my $opac_app = builder { > enable "Plack::Middleware::Static", >@@ -137,6 +141,8 @@ use Plack::App::URLMap; > > =cut > >+# We cannot store whole Context object, may contain non-serializable things >+my @CONTEXT_UNSAFE_PROPERTIES = qw(sysprefs); > sub app_per_host { > my $class = shift; > my $sites = shift or die "No sites spec"; >@@ -148,12 +154,43 @@ sub app_per_host { > > my $app = $site_params->{app} or croak "No app"; > my $context = $site_params->{context} or croak "No Koha Context"; >+ my $shared_context = $site_params->{shared_context}; >+ my $cache = $context->memcached; >+ if ($shared_context) { >+ if ($cache) { >+ foreach (@CONTEXT_UNSAFE_PROPERTIES) { >+ # Clean slate >+ $cache->clear_from_cache($_); >+ } >+ } >+ else { >+ warn "shared_context works only with memcached"; >+ } >+ } > > foreach my $host (@$hosts) { > $map->map("http://$host/" => sub { > my $env = shift; > >- return $context->run_within_context(sub { $app->($env) }); >+ # may have stopped meanwhile or whatever >+ my $cache = $context->memcached; >+ if ($shared_context && $cache) { >+ foreach (@CONTEXT_UNSAFE_PROPERTIES) { >+ if (my $shared = $cache->get($_)) { >+ $context->{$_} = $shared; >+ } >+ } >+ } >+ >+ my $ret = $context->run_within_context(sub { $app->($env) }); >+ >+ if ($shared_context && $cache) { >+ foreach (@CONTEXT_UNSAFE_PROPERTIES) { >+ $cache->set($_, $context->{$_}); >+ } >+ } >+ >+ $ret; > }); > } > } >diff --git a/Koha/Handler/Plack/CGI.pm b/Koha/Handler/Plack/CGI.pm >index 36c6907..9892562 100644 >--- a/Koha/Handler/Plack/CGI.pm >+++ b/Koha/Handler/Plack/CGI.pm >@@ -73,7 +73,7 @@ use Plack::App::CGIBin; > > use parent "Koha::Handler::Plack"; > >-use C4::Context; >+use C4::Context ":no_config"; > > =head1 CLASS METHODS > >diff --git a/Koha/MetaSearcher.pm b/Koha/MetaSearcher.pm >index ce5add4..5349daa 100644 >--- a/Koha/MetaSearcher.pm >+++ b/Koha/MetaSearcher.pm >@@ -25,7 +25,7 @@ use C4::Charset qw( MarcToUTF8Record ); > use C4::Search qw(); # Purely for new_record_from_zebra > use DBIx::Class::ResultClass::HashRefInflator; > use IO::Select; >-use Koha::Caches; >+use C4::Context; > use Koha::Database; > use Koha::MetadataRecord; > use MARC::File::XML; >@@ -91,7 +91,7 @@ sub search { > > my $resultset_expiry = 300; > >- my $cache = Koha::Caches->get_instance(); >+ my $cache = C4::Context->cache; > my $schema = Koha::Database->new->schema; > my $stats = { > num_fetched => { >diff --git a/Koha/Template/Plugin/Cache.pm b/Koha/Template/Plugin/Cache.pm >index 5e3f8f7..4c88b80 100644 >--- a/Koha/Template/Plugin/Cache.pm >+++ b/Koha/Template/Plugin/Cache.pm >@@ -21,7 +21,6 @@ use strict; > use warnings; > use base qw( Template::Plugin ); > use Template::Plugin; >-use C4::Context; > > #------------------------------------------------------------------------ > # new(\%options) >@@ -34,8 +33,7 @@ sub new { > $cache = delete $params->{cache}; > } > else { >- require Koha::Cache; >- $cache = Koha::Caches->get_instance(); >+ $cache = $context->cache; > } > my $self = bless { > CACHE => $cache, >diff --git a/admin/biblio_framework.pl b/admin/biblio_framework.pl >index dd4af97..e496bd8 100755 >--- a/admin/biblio_framework.pl >+++ b/admin/biblio_framework.pl >@@ -26,12 +26,11 @@ use C4::Output; > use Koha::Biblios; > use Koha::BiblioFramework; > use Koha::BiblioFrameworks; >-use Koha::Caches; > > my $input = new CGI; > my $frameworkcode = $input->param('frameworkcode') || q||; > my $op = $input->param('op') || q|list|; >-my $cache = Koha::Caches->get_instance(); >+my $cache = C4::Context->cache; > my @messages; > > my ( $template, $borrowernumber, $cookie ) = get_template_and_user( >diff --git a/admin/koha2marclinks.pl b/admin/koha2marclinks.pl >index d8fd569..68f1e55 100755 >--- a/admin/koha2marclinks.pl >+++ b/admin/koha2marclinks.pl >@@ -59,7 +59,7 @@ else { > } > > my $dbh = C4::Context->dbh; >-my $cache = Koha::Caches->get_instance(); >+my $cache = C4::Context->cache; > > ################## ADD_FORM ################################## > # called by default. Used to create form to add or modify a record >diff --git a/admin/marc_subfields_structure.pl b/admin/marc_subfields_structure.pl >index 38e6f24..a8a9dba 100755 >--- a/admin/marc_subfields_structure.pl >+++ b/admin/marc_subfields_structure.pl >@@ -77,7 +77,7 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( > debug => 1, > } > ); >-my $cache = Koha::Caches->get_instance(); >+my $cache = C4::Context->cache; > > my $op = $input->param('op') || ""; > $tagfield =~ s/\,//g; >diff --git a/admin/marctagstructure.pl b/admin/marctagstructure.pl >index 784fb50..46126e9 100755 >--- a/admin/marctagstructure.pl >+++ b/admin/marctagstructure.pl >@@ -25,9 +25,6 @@ use C4::Auth; > use C4::Koha; > use C4::Context; > use C4::Output; >-use C4::Context; >- >-use Koha::Caches; > > # retrieve parameters > my $input = new CGI; >@@ -46,7 +43,7 @@ my $pagesize = 20; > my $script_name = "/cgi-bin/koha/admin/marctagstructure.pl"; > > my $dbh = C4::Context->dbh; >-my $cache = Koha::Caches->get_instance(); >+my $cache = C4::Context->cache; > > # open template > my ($template, $loggedinuser, $cookie) >diff --git a/opac/svc/report b/opac/svc/report >index d2f953d..98d2aeb 100755 >--- a/opac/svc/report >+++ b/opac/svc/report >@@ -23,12 +23,11 @@ > > use Modern::Perl; > >+use C4::Context; > use C4::Reports::Guided; > use JSON; > use CGI qw ( -utf8 ); > >-use Koha::Caches; >- > my $query = CGI->new(); > my $report_id = $query->param('id'); > my $report_name = $query->param('name'); >@@ -41,7 +40,7 @@ die "Sorry this report is not public\n" unless $report_rec->{public}; > > my @sql_params = $query->param('sql_params'); > >-my $cache = Koha::Caches->get_instance(); >+my $cache = C4::Context->cache; > my $cache_active = $cache->is_cache_active; > my ($cache_key, $json_text); > if ($cache_active) { >diff --git a/reports/guided_reports.pl b/reports/guided_reports.pl >index a9963db..2bb72b1 100755 >--- a/reports/guided_reports.pl >+++ b/reports/guided_reports.pl >@@ -30,7 +30,6 @@ use C4::Output; > use C4::Debug; > use C4::Koha qw/GetFrameworksLoop/; > use C4::Context; >-use Koha::Caches; > use C4::Log; > use Koha::DateUtils qw/dt_from_string output_pref/; > use Koha::AuthorisedValue; >@@ -49,7 +48,7 @@ Script to control the guided report creation > =cut > > my $input = new CGI; >-my $usecache = Koha::Caches->get_instance->memcached_cache; >+my $usecache = C4::Context->cache->memcached_cache; > > my $phase = $input->param('phase') // ''; > my $flagsrequired; >diff --git a/svc/report b/svc/report >index 8a8bc26..d380090 100755 >--- a/svc/report >+++ b/svc/report >@@ -25,7 +25,7 @@ use C4::Reports::Guided; > use JSON; > use CGI qw ( -utf8 ); > >-use Koha::Caches; >+use C4::Context; > > > my $query = CGI->new(); >@@ -48,7 +48,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > } > ); > >-my $cache = Koha::Caches->get_instance(); >+my $cache = C4::Context->cache; > my $cache_active = $cache->is_cache_active; > my ($cache_key, $json_text); > if ($cache_active) { >diff --git a/t/Calendar.t b/t/Calendar.t >index 3082271..55f5d89 100755 >--- a/t/Calendar.t >+++ b/t/Calendar.t >@@ -22,7 +22,7 @@ use Test::MockModule; > > use DateTime; > use DateTime::Duration; >-use Koha::Caches; >+use C4::Context; > use Koha::DateUtils; > > use Module::Load::Conditional qw/check_install/; >@@ -89,7 +89,7 @@ fixtures_ok [ > ], > ], "add fixtures"; > >-my $cache = Koha::Caches->get_instance(); >+my $cache = C4::Context->cache; > $cache->clear_from_cache( 'single_holidays') ; > > # 'MPL' branch is arbitrary, is not used at all but is needed for initialization >diff --git a/t/Context.t b/t/Context.t >index e2c1825..d737509 100755 >--- a/t/Context.t >+++ b/t/Context.t >@@ -2,7 +2,7 @@ > > use Modern::Perl; > use DBI; >-use Test::More tests => 26; >+use Test::More tests => 29; > use Test::MockModule; > > BEGIN { >@@ -62,3 +62,29 @@ is(C4::Context->interface, 'opac', 'interface still opac'); > #Bug 14751 > is( C4::Context->interface( 'SiP' ), 'sip', 'interface SiP' ); > is( C4::Context->interface( 'COMMANDLINE' ), 'commandline', 'interface commandline uc' ); >+ >+my $DUMMY_KOHA_CONF = "<yazgfs><config><kohasite>TEST</kohasite></config></yazgfs>"; >+my $ctx_a = C4::Context->new($DUMMY_KOHA_CONF, "a"); >+my $ctx_b = C4::Context->new($DUMMY_KOHA_CONF, "b"); >+my $cache_key = "test_C4::Context"; >+ >+SKIP: { >+ skip "No cache", 3 unless $ctx_a->cache->is_cache_active && $ctx_b->cache->is_cache_active; >+ >+ # Light warm up >+ C4::Context->cache->set_in_cache($cache_key, 'c'); >+ $ctx_a->cache->set_in_cache($cache_key, 'a'); >+ $ctx_b->cache->set_in_cache($cache_key, 'b'); >+ is(C4::Context->cache->get_from_cache($cache_key), 'c', "Correct default cache value"); >+ is($ctx_a->cache->get_from_cache($cache_key), 'a', "Correct cache 'a' value"); >+ is($ctx_b->cache->get_from_cache($cache_key), 'b', "Correct cache 'b' value"); >+ >+ # A bit more extravagant >+ # Cannot run atm, fails due to no database in config >+# $ctx_a->run_within_context( sub { >+# $ctx_b->cache->set_in_cache($cache_key, 'bb'); >+# C4::Context->cache->set_in_cache($cache_key, 'aa'); >+# } ); >+# is($ctx_a->cache->get_from_cache($cache_key), 'aa', "Correct cache 'a' value"); >+# is($ctx_b->cache->get_from_cache($cache_key), 'bb', "Correct cache 'b' value"); >+} >diff --git a/t/Koha_Template_Plugin_Cache.t b/t/Koha_Template_Plugin_Cache.t >index da20f61..15ee048 100644 >--- a/t/Koha_Template_Plugin_Cache.t >+++ b/t/Koha_Template_Plugin_Cache.t >@@ -1,6 +1,8 @@ > use Modern::Perl; > use Test::More tests => 2; > >+use C4::Context; >+ > use_ok('Koha::Template::Plugin::Cache'); > >-ok(my $cache = Koha::Template::Plugin::Cache->new()); >+ok(my $cache = Koha::Template::Plugin::Cache->new(C4::Context->current)); >diff --git a/t/db_dependent/Context.t b/t/db_dependent/Context.t >index c9d78ea..1765e0f 100755 >--- a/t/db_dependent/Context.t >+++ b/t/db_dependent/Context.t >@@ -12,14 +12,8 @@ use Koha::Database; > > BEGIN { > $debug = $ENV{DEBUG} || 0; >- >- # Note: The overall number of tests may vary by configuration. >- # First we need to check your environmental variables >- for (qw(KOHA_CONF PERL5LIB)) { >- ok( $ret = $ENV{$_}, "ENV{$_} = $ret" ); >- } >- use_ok('C4::Context'); > } >+use_ok('C4::Context'); > > ok($dbh = C4::Context->dbh(), 'Getting dbh from C4::Context'); > >diff --git a/t/db_dependent/Filter_MARC_ViewPolicy.t b/t/db_dependent/Filter_MARC_ViewPolicy.t >index bd684b6..b24c9f3 100644 >--- a/t/db_dependent/Filter_MARC_ViewPolicy.t >+++ b/t/db_dependent/Filter_MARC_ViewPolicy.t >@@ -30,7 +30,6 @@ use MARC::Record; > use MARC::Field; > use C4::Context; > use C4::Biblio; >-use Koha::Caches; > use Koha::Database; > > BEGIN { >@@ -66,7 +65,7 @@ sub run_hiding_tests { > > $sth->execute($hidden_value); > >- my $cache = Koha::Caches->get_instance(); >+ my $cache = C4::Context->cache; > $cache->flush_all(); # easy way to ensure DB is queried again. > > my $processor = Koha::RecordProcessor->new( >@@ -138,7 +137,7 @@ sub run_hiding_tests { > > $sth->execute(-1); # -1 is visible in opac and intranet. > >- my $cache = Koha::Caches->get_instance(); >+ my $cache = C4::Context->cache; > $cache->flush_all(); # easy way to ensure DB is queried again. > > my $shouldhidemarc = Koha::Filter::MARC::ViewPolicy->should_hide_marc( >diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t >index 3e886e2..a927c4c 100755 >--- a/t/db_dependent/Items.t >+++ b/t/db_dependent/Items.t >@@ -19,6 +19,7 @@ > use Modern::Perl; > > use MARC::Record; >+use C4::Context; > use C4::Biblio; > use Koha::Database; > use Koha::Library; >@@ -380,7 +381,7 @@ subtest 'SearchItems test' => sub { > $dbh->do('INSERT INTO marc_subfield_structure (tagfield, tagsubfield, frameworkcode) VALUES (?, "z", ?)', undef, $itemfield, $frameworkcode); > > # Clear cache >- my $cache = Koha::Caches->get_instance(); >+ my $cache = C4::Context->cache; > $cache->clear_from_cache("MarcStructure-0-$frameworkcode"); > $cache->clear_from_cache("MarcStructure-1-$frameworkcode"); > $cache->clear_from_cache("default_value_for_mod_marc-$frameworkcode"); >@@ -644,7 +645,7 @@ subtest 'C4::Items::_build_default_values_for_mod_marc' => sub { > |, undef, $framework->{frameworkcode} ); > > # And make sure the caches are cleared >- my $cache = Koha::Caches->get_instance(); >+ my $cache = C4::Context->cache; > $cache->clear_from_cache("MarcStructure-0-" . $framework->{frameworkcode}); > $cache->clear_from_cache("MarcStructure-1-" . $framework->{frameworkcode}); > $cache->clear_from_cache("default_value_for_mod_marc-" . $framework->{frameworkcode}); >diff --git a/tools/newHolidays.pl b/tools/newHolidays.pl >index eb948c7..5a9eeda 100755 >--- a/tools/newHolidays.pl >+++ b/tools/newHolidays.pl >@@ -10,7 +10,7 @@ use CGI qw ( -utf8 ); > use C4::Auth; > use C4::Output; > >-use Koha::Caches; >+use C4::Context; > > use C4::Calendar; > use DateTime; >@@ -128,6 +128,6 @@ sub add_holiday { > } > } > # we updated the single_holidays table, so wipe its cache >- my $cache = Koha::Caches->get_instance(); >+ my $cache = C4::Context->cache; > $cache->clear_from_cache( 'single_holidays') ; > } >-- >2.7.4
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 15562
:
47420
|
47421
|
47422
|
47838
|
47944
|
47945
|
47946
|
47947
|
49370
|
49371
|
49372
|
49373
|
49664
|
49665
|
49666
|
49667
|
49709
|
50702
|
50703
|
50713
|
50714
|
50715
|
50716
|
50870
|
51939
|
51940
|
53296
|
53297
|
55577
|
55578
|
60723
|
60724
|
60725
|
60726
|
66374
|
66375
|
66376
|
66377
|
76062