View | Details | Raw Unified | Return to bug 15562
Collapse All | Expand All

(-)a/C4/Auth.pm (-5 / +5 lines)
Lines 31-37 use C4::Templates; # to get the template Link Here
31
use C4::Languages;
31
use C4::Languages;
32
use C4::Search::History;
32
use C4::Search::History;
33
use Koha;
33
use Koha;
34
use Koha::Caches;
35
use Koha::AuthUtils qw(get_script_name hash_password);
34
use Koha::AuthUtils qw(get_script_name hash_password);
36
use Koha::Libraries;
35
use Koha::Libraries;
37
use Koha::LibraryCategories;
36
use Koha::LibraryCategories;
Lines 1706-1716 sub get_session { Link Here
1706
    elsif ( $storage_method eq 'Pg' ) {
1705
    elsif ( $storage_method eq 'Pg' ) {
1707
        $session = new CGI::Session( "driver:PostgreSQL;serializer:yaml;id:md5", $sessionID, { Handle => $dbh } );
1706
        $session = new CGI::Session( "driver:PostgreSQL;serializer:yaml;id:md5", $sessionID, { Handle => $dbh } );
1708
    }
1707
    }
1709
    elsif ( $storage_method eq 'memcached' && Koha::Caches->get_instance->memcached_cache ) {
1708
    elsif ( $storage_method eq 'memcached' ) {
1710
        my $memcached = Koha::Caches->get_instance()->memcached_cache;
1709
        if ( my $memcached = C4::Context->cache->memcached_cache ) {
1711
        $session = new CGI::Session( "driver:memcached;serializer:yaml;id:md5", $sessionID, { Memcached => $memcached } );
1710
            $session = new CGI::Session( "driver:memcached;serializer:yaml;id:md5", $sessionID, { Memcached => $memcached } );
1711
        }
1712
    }
1712
    }
1713
    else {
1713
    unless ($session) {
1714
        # catch all defaults to tmp should work on all systems
1714
        # catch all defaults to tmp should work on all systems
1715
        my $dir = File::Spec->tmpdir;
1715
        my $dir = File::Spec->tmpdir;
1716
        my $instance = C4::Context->config( 'database' ); #actually for packages not exactly the instance name, but generally safer to leave it as it is
1716
        my $instance = C4::Context->config( 'database' ); #actually for packages not exactly the instance name, but generally safer to leave it as it is
(-)a/C4/Biblio.pm (-3 / +3 lines)
Lines 37-44 use C4::Charset; Link Here
37
use C4::Linker;
37
use C4::Linker;
38
use C4::OAI::Sets;
38
use C4::OAI::Sets;
39
use C4::Debug;
39
use C4::Debug;
40
use C4::Context;
40
41
41
use Koha::Caches;
42
use Koha::Authority::Types;
42
use Koha::Authority::Types;
43
use Koha::Acquisition::Currencies;
43
use Koha::Acquisition::Currencies;
44
use Koha::Biblio::Metadata;
44
use Koha::Biblio::Metadata;
Lines 1107-1113 sub GetMarcStructure { Link Here
1107
1107
1108
    $forlibrarian = $forlibrarian ? 1 : 0;
1108
    $forlibrarian = $forlibrarian ? 1 : 0;
1109
    my $unsafe = ($params && $params->{unsafe})? 1: 0;
1109
    my $unsafe = ($params && $params->{unsafe})? 1: 0;
1110
    my $cache = Koha::Caches->get_instance();
1110
    my $cache = C4::Context->cache;
1111
    my $cache_key = "MarcStructure-$forlibrarian-$frameworkcode";
1111
    my $cache_key = "MarcStructure-$forlibrarian-$frameworkcode";
1112
    my $cached = $cache->get_from_cache($cache_key, { unsafe => $unsafe });
1112
    my $cached = $cache->get_from_cache($cache_key, { unsafe => $unsafe });
1113
    return $cached if $cached;
1113
    return $cached if $cached;
Lines 1215-1221 sub GetMarcSubfieldStructure { Link Here
1215
1215
1216
    $frameworkcode //= '';
1216
    $frameworkcode //= '';
1217
1217
1218
    my $cache     = Koha::Caches->get_instance();
1218
    my $cache     = C4::Context->cache;
1219
    my $cache_key = "MarcSubfieldStructure-$frameworkcode";
1219
    my $cache_key = "MarcSubfieldStructure-$frameworkcode";
1220
    my $cached    = $cache->get_from_cache($cache_key);
1220
    my $cached    = $cache->get_from_cache($cache_key);
1221
    return $cached if $cached;
1221
    return $cached if $cached;
(-)a/C4/Calendar.pm (-8 / +7 lines)
Lines 23-29 use Carp; Link Here
23
use Date::Calc qw( Date_to_Days Today);
23
use Date::Calc qw( Date_to_Days Today);
24
24
25
use C4::Context;
25
use C4::Context;
26
use Koha::Caches;
27
26
28
use constant ISO_DATE_FORMAT => "%04d-%02d-%02d";
27
use constant ISO_DATE_FORMAT => "%04d-%02d-%02d";
29
28
Lines 276-282 sub insert_single_holiday { Link Here
276
275
277
276
278
    # changed the 'single_holidays' table, lets force/reset its cache
277
    # changed the 'single_holidays' table, lets force/reset its cache
279
    my $cache = Koha::Caches->get_instance();
278
    my $cache = C4::Context->cache;
280
    $cache->clear_from_cache( 'single_holidays') ;
279
    $cache->clear_from_cache( 'single_holidays') ;
281
    $cache->clear_from_cache( 'exception_holidays') ;
280
    $cache->clear_from_cache( 'exception_holidays') ;
282
281
Lines 321-327 sub insert_exception_holiday { Link Here
321
    $self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description};
320
    $self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description};
322
321
323
    # changed the 'single_holidays' table, lets force/reset its cache
322
    # changed the 'single_holidays' table, lets force/reset its cache
324
    my $cache = Koha::Caches->get_instance();
323
    my $cache = C4::Context->cache;
325
    $cache->clear_from_cache( 'single_holidays') ;
324
    $cache->clear_from_cache( 'single_holidays') ;
326
    $cache->clear_from_cache( 'exception_holidays') ;
325
    $cache->clear_from_cache( 'exception_holidays') ;
327
326
Lines 422-428 UPDATE special_holidays SET title = ?, description = ? Link Here
422
    $self->{'single_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description};
421
    $self->{'single_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description};
423
422
424
    # changed the 'single_holidays' table, lets force/reset its cache
423
    # changed the 'single_holidays' table, lets force/reset its cache
425
    my $cache = Koha::Caches->get_instance();
424
    my $cache = C4::Context->cache;
426
    $cache->clear_from_cache( 'single_holidays') ;
425
    $cache->clear_from_cache( 'single_holidays') ;
427
    $cache->clear_from_cache( 'exception_holidays') ;
426
    $cache->clear_from_cache( 'exception_holidays') ;
428
427
Lines 465-471 UPDATE special_holidays SET title = ?, description = ? Link Here
465
    $self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description};
464
    $self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description};
466
465
467
    # changed the 'single_holidays' table, lets force/reset its cache
466
    # changed the 'single_holidays' table, lets force/reset its cache
468
    my $cache = Koha::Caches->get_instance();
467
    my $cache = C4::Context->cache;
469
    $cache->clear_from_cache( 'single_holidays') ;
468
    $cache->clear_from_cache( 'single_holidays') ;
470
    $cache->clear_from_cache( 'exception_holidays') ;
469
    $cache->clear_from_cache( 'exception_holidays') ;
471
470
Lines 546-552 sub delete_holiday { Link Here
546
    }
545
    }
547
546
548
    # changed the 'single_holidays' table, lets force/reset its cache
547
    # changed the 'single_holidays' table, lets force/reset its cache
549
    my $cache = Koha::Caches->get_instance();
548
    my $cache = C4::Context->cache;
550
    $cache->clear_from_cache( 'single_holidays') ;
549
    $cache->clear_from_cache( 'single_holidays') ;
551
    $cache->clear_from_cache( 'exception_holidays') ;
550
    $cache->clear_from_cache( 'exception_holidays') ;
552
551
Lines 577-583 sub delete_holiday_range { Link Here
577
    $sth->execute($self->{branchcode}, $options{day}, $options{month}, $options{year});
576
    $sth->execute($self->{branchcode}, $options{day}, $options{month}, $options{year});
578
577
579
    # changed the 'single_holidays' table, lets force/reset its cache
578
    # changed the 'single_holidays' table, lets force/reset its cache
580
    my $cache = Koha::Caches->get_instance();
579
    my $cache = C4::Context->cache;
581
    $cache->clear_from_cache( 'single_holidays') ;
580
    $cache->clear_from_cache( 'single_holidays') ;
582
    $cache->clear_from_cache( 'exception_holidays') ;
581
    $cache->clear_from_cache( 'exception_holidays') ;
583
582
Lines 631-637 sub delete_exception_holiday_range { Link Here
631
    $sth->execute($self->{branchcode}, $options{day}, $options{month}, $options{year});
630
    $sth->execute($self->{branchcode}, $options{day}, $options{month}, $options{year});
632
631
633
    # changed the 'single_holidays' table, lets force/reset its cache
632
    # changed the 'single_holidays' table, lets force/reset its cache
634
    my $cache = Koha::Caches->get_instance();
633
    my $cache = C4::Context->cache;
635
    $cache->clear_from_cache( 'single_holidays') ;
634
    $cache->clear_from_cache( 'single_holidays') ;
636
    $cache->clear_from_cache( 'exception_holidays') ;
635
    $cache->clear_from_cache( 'exception_holidays') ;
637
}
636
}
(-)a/C4/Context.pm (-1 / +28 lines)
Lines 178-183 sub current { Link Here
178
    return $context;
178
    return $context;
179
}
179
}
180
180
181
=head2 cache
182
183
Returns the cache object or undef
184
185
=cut
186
187
sub cache {
188
    my $self = shift;
189
    $self = $context unless ref ($self);
190
191
    return Koha::Caches->get_instance($self->{namespace});
192
}
193
194
=head2 memcached
195
196
Returns the cache object if it is memcached or undef
197
198
=cut
199
200
sub memcached {
201
    my $self = shift;
202
    my $cache = $self->cache;
203
    return $cache if $cache->memcached_cache;
204
205
    return;
206
}
207
181
sub db_driver {
208
sub db_driver {
182
    my $self = shift;
209
    my $self = shift;
183
210
Lines 496-503 used with Plack and other persistent environments. Link Here
496
sub disable_syspref_cache {
523
sub disable_syspref_cache {
497
    my ($self) = @_;
524
    my ($self) = @_;
498
    $self = $context unless ref $self;
525
    $self = $context unless ref $self;
499
    $self->{use_syspref_cache} = 0;
500
    $self->clear_syspref_cache();
526
    $self->clear_syspref_cache();
527
    $self->{use_syspref_cache} = 0;
501
}
528
}
502
529
503
=head2 clear_syspref_cache
530
=head2 clear_syspref_cache
(-)a/C4/External/OverDrive.pm (-4 / +2 lines)
Lines 22-28 use warnings; Link Here
22
22
23
use Koha;
23
use Koha;
24
use JSON;
24
use JSON;
25
use Koha::Caches;
25
use C4::Context;
26
use HTTP::Request;
26
use HTTP::Request;
27
use HTTP::Request::Common;
27
use HTTP::Request::Common;
28
use LWP::Authen::Basic;
28
use LWP::Authen::Basic;
Lines 97-105 sub GetOverDriveToken { Link Here
97
97
98
    return unless ( $key && $secret ) ;
98
    return unless ( $key && $secret ) ;
99
99
100
    my $cache;
100
    my $cache = C4::Context->cache;
101
102
    eval { $cache = Koha::Caches->get_instance() };
103
101
104
    my $token;
102
    my $token;
105
    $cache and $token = $cache->get_from_cache( "overdrive_token" ) and return $token;
103
    $cache and $token = $cache->get_from_cache( "overdrive_token" ) and return $token;
(-)a/C4/Items.pm (-1 / +1 lines)
Lines 449-455 Returns item record Link Here
449
sub _build_default_values_for_mod_marc {
449
sub _build_default_values_for_mod_marc {
450
    my ($frameworkcode) = @_;
450
    my ($frameworkcode) = @_;
451
451
452
    my $cache     = Koha::Caches->get_instance();
452
    my $cache     = C4::Context->cache;
453
    my $cache_key = "default_value_for_mod_marc-$frameworkcode";
453
    my $cache_key = "default_value_for_mod_marc-$frameworkcode";
454
    my $cached    = $cache->get_from_cache($cache_key);
454
    my $cached    = $cache->get_from_cache($cache_key);
455
    return $cached if $cached;
455
    return $cached if $cached;
(-)a/C4/Koha.pm (-2 / +1 lines)
Lines 24-30 use strict; Link Here
24
#use warnings; FIXME - Bug 2505
24
#use warnings; FIXME - Bug 2505
25
25
26
use C4::Context;
26
use C4::Context;
27
use Koha::Caches;
28
use Koha::DateUtils qw(dt_from_string);
27
use Koha::DateUtils qw(dt_from_string);
29
use Koha::AuthorisedValues;
28
use Koha::AuthorisedValues;
30
use Koha::Libraries;
29
use Koha::Libraries;
Lines 710-716 sub GetAuthorisedValues { Link Here
710
      C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
709
      C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
711
    my $cache_key =
710
    my $cache_key =
712
      "AuthorisedValues-$category-$opac-$branch_limit";
711
      "AuthorisedValues-$category-$opac-$branch_limit";
713
    my $cache  = Koha::Caches->get_instance();
712
    my $cache  = C4::Context->cache;
714
    my $result = $cache->get_from_cache($cache_key);
713
    my $result = $cache->get_from_cache($cache_key);
715
    return $result if $result;
714
    return $result if $result;
716
715
(-)a/C4/Utils/DataTables/ColumnsSettings.pm (-2 / +1 lines)
Lines 5-15 use List::Util qw( first ); Link Here
5
use YAML;
5
use YAML;
6
use C4::Context;
6
use C4::Context;
7
use Koha::Database;
7
use Koha::Database;
8
use Koha::Caches;
9
8
10
sub get_yaml {
9
sub get_yaml {
11
    my $yml_path = C4::Context->config('intranetdir') . '/admin/columns_settings.yml';
10
    my $yml_path = C4::Context->config('intranetdir') . '/admin/columns_settings.yml';
12
    my $cache = Koha::Caches->get_instance();
11
    my $cache = C4::Context->cache;
13
    my $yaml  = $cache->get_from_cache('ColumnsSettingsYaml');
12
    my $yaml  = $cache->get_from_cache('ColumnsSettingsYaml');
14
13
15
    unless ($yaml) {
14
    unless ($yaml) {
(-)a/Koha/Cache.pm (-16 / +17 lines)
Lines 64-97 Create a new Koha::Cache object. This is required for all cache-related function Link Here
64
=cut
64
=cut
65
65
66
sub new {
66
sub new {
67
    my ( $class, $self, $params ) = @_;
67
    my ( $class, $self ) = @_;
68
    $self->{'default_type'} =
68
    $self->{'default_type'} =
69
         $self->{cache_type}
69
         $self->{cache_type}
70
      || $ENV{CACHING_SYSTEM} # DELME What about this?
70
      || $ENV{CACHING_SYSTEM} # DELME What about this?
71
      || 'memcached';
71
      || 'memcached';
72
72
73
    my $subnamespace = $params->{subnamespace} // '';
73
    $self->{namespace} //= '';
74
74
75
    $ENV{DEBUG} && carp "Default caching system: $self->{'default_type'}";
75
    $ENV{DEBUG} && carp "Default caching system: $self->{'default_type'}";
76
76
77
    $self->{'timeout'}   ||= 0;
77
    $self->{'timeout'}   ||= 0;
78
    # Should we continue to support MEMCACHED ENV vars?
79
    $self->{'namespace'} ||= $ENV{MEMCACHED_NAMESPACE};
80
    my @servers = split /,/, $ENV{MEMCACHED_SERVERS} || '';
81
    unless ( $self->{namespace} and @servers ) {
82
        my $koha_config = Koha::Config->read_from_file( Koha::Config->guess_koha_conf() );
83
        $self->{namespace} ||= $koha_config->{config}{memcached_namespace} || 'koha';
84
        @servers = split /,/, $koha_config->{config}{memcached_servers} // ''
85
            unless @servers;
86
    }
87
    $self->{namespace} .= ":$subnamespace:";
88
78
89
    if ( $self->{'default_type'} eq 'memcached'
79
    if ( $self->{'default_type'} eq 'memcached'
90
        && can_load( modules => { 'Cache::Memcached::Fast' => undef } )
80
        && can_load( modules => { 'Cache::Memcached::Fast' => undef } ) )
91
        && _initialize_memcached($self, @servers)
92
        && defined( $self->{'memcached_cache'} ) )
93
    {
81
    {
94
        $self->{'cache'} = $self->{'memcached_cache'};
82
        # Should we continue to support MEMCACHED ENV vars?
83
        $self->{'namespace'} ||= $ENV{MEMCACHED_NAMESPACE};
84
        my @servers = split /,/, $ENV{MEMCACHED_SERVERS} || '';
85
        unless ( $self->{namespace} && @servers ) {
86
            my $koha_config = Koha::Config->read_from_file( Koha::Config->guess_koha_conf() );
87
            $self->{namespace} ||= $koha_config->{config}{memcached_namespace} || 'koha';
88
            @servers = split /,/, $koha_config->{config}{memcached_servers} // ''
89
                unless @servers;
90
        }
91
        if ( _initialize_memcached($self, @servers)
92
            && defined( $self->{'memcached_cache'} ) )
93
        {
94
            $self->{'cache'} = $self->{'memcached_cache'};
95
        }
95
    }
96
    }
96
97
97
    if ( $self->{'default_type'} eq 'fastmmap'
98
    if ( $self->{'default_type'} eq 'fastmmap'
(-)a/Koha/Caches.pm (-1 / +1 lines)
Lines 58-64 sub get_instance { Link Here
58
=cut
58
=cut
59
59
60
sub flush_L1_caches {
60
sub flush_L1_caches {
61
    my ($class, $subnamespace, $namespace) = @_;
61
    my ($class, $namespace) = @_;
62
    $namespace //= '';
62
    $namespace //= '';
63
63
64
    return unless $singleton_caches;
64
    return unless $singleton_caches;
(-)a/Koha/Calendar.pm (-3 / +2 lines)
Lines 7-13 use DateTime; Link Here
7
use DateTime::Set;
7
use DateTime::Set;
8
use DateTime::Duration;
8
use DateTime::Duration;
9
use C4::Context;
9
use C4::Context;
10
use Koha::Caches;
11
use Carp;
10
use Carp;
12
11
13
sub new {
12
sub new {
Lines 55-61 sub _init { Link Here
55
sub exception_holidays {
54
sub exception_holidays {
56
    my ( $self ) = @_;
55
    my ( $self ) = @_;
57
56
58
    my $cache  = Koha::Caches->get_instance();
57
    my $cache  = C4::Context->cache;
59
    my $cached = $cache->get_from_cache('exception_holidays');
58
    my $cached = $cache->get_from_cache('exception_holidays');
60
    return $cached if $cached;
59
    return $cached if $cached;
61
60
Lines 84-90 sub exception_holidays { Link Here
84
sub single_holidays {
83
sub single_holidays {
85
    my ( $self, $date ) = @_;
84
    my ( $self, $date ) = @_;
86
    my $branchcode = $self->{branchcode};
85
    my $branchcode = $self->{branchcode};
87
    my $cache           = Koha::Caches->get_instance();
86
    my $cache           = C4::Context->cache;
88
    my $single_holidays = $cache->get_from_cache('single_holidays');
87
    my $single_holidays = $cache->get_from_cache('single_holidays');
89
88
90
    # $single_holidays looks like:
89
    # $single_holidays looks like:
(-)a/Koha/Handler/Plack.pm (-2 / +39 lines)
Lines 69-74 use Plack::App::URLMap; Link Here
69
          hostname => 'koha1.com',
69
          hostname => 'koha1.com',
70
          app => $app1,
70
          app => $app1,
71
          context => $context1,
71
          context => $context1,
72
          shared_context => 1
72
      },
73
      },
73
      {
74
      {
74
          hostname => ['koha2.com', 'www.koha2.com'],
75
          hostname => ['koha2.com', 'www.koha2.com'],
Lines 78-90 use Plack::App::URLMap; Link Here
78
      ...
79
      ...
79
80
80
  C<hostname> is mandatory.
81
  C<hostname> is mandatory.
82
  If C<shared_context> is set to true, some Context properties will be preserved across
83
  forked processes. Useful if both OPAC and Intranet apps are served here, so no restart
84
  is needed when Context cached properties cnamge values. Needs memcached.
81
85
82
  koha.psgi:
86
  koha.psgi:
83
87
84
  use Plack::Builder;
88
  use Plack::Builder;
85
  use Plack::App::CGIBin;
89
  use Plack::App::CGIBin;
86
90
87
  use C4::Context;
91
  use C4::Context ":no_config";
88
92
89
  my $opac_app = builder {
93
  my $opac_app = builder {
90
      enable "Plack::Middleware::Static",
94
      enable "Plack::Middleware::Static",
Lines 137-142 use Plack::App::URLMap; Link Here
137
141
138
=cut
142
=cut
139
143
144
# We cannot store whole Context object, may contain non-serializable things
145
my @CONTEXT_UNSAFE_PROPERTIES = qw(sysprefs);
140
sub app_per_host {
146
sub app_per_host {
141
    my $class = shift;
147
    my $class = shift;
142
    my $sites = shift or die "No sites spec";
148
    my $sites = shift or die "No sites spec";
Lines 148-159 sub app_per_host { Link Here
148
154
149
        my $app = $site_params->{app} or croak "No app";
155
        my $app = $site_params->{app} or croak "No app";
150
        my $context = $site_params->{context} or croak "No Koha Context";
156
        my $context = $site_params->{context} or croak "No Koha Context";
157
        my $shared_context = $site_params->{shared_context};
158
        my $cache = $context->memcached;
159
        if ($shared_context) {
160
            if ($cache) {
161
                foreach (@CONTEXT_UNSAFE_PROPERTIES) {
162
                    # Clean slate
163
                    $cache->clear_from_cache($_);
164
                }
165
            }
166
            else {
167
                warn "shared_context works only with memcached";
168
            }
169
        }
151
170
152
        foreach my $host (@$hosts) {
171
        foreach my $host (@$hosts) {
153
            $map->map("http://$host/" => sub {
172
            $map->map("http://$host/" => sub {
154
                my $env = shift;
173
                my $env = shift;
155
174
156
                return $context->run_within_context(sub { $app->($env) });
175
                # may have stopped meanwhile or whatever
176
                my $cache = $context->memcached;
177
                if ($shared_context && $cache) {
178
                    foreach (@CONTEXT_UNSAFE_PROPERTIES) {
179
                        if (my $shared = $cache->get($_)) {
180
                            $context->{$_} = $shared;
181
                        }
182
                    }
183
                }
184
185
                my $ret = $context->run_within_context(sub { $app->($env) });
186
187
                if ($shared_context && $cache) {
188
                    foreach (@CONTEXT_UNSAFE_PROPERTIES) {
189
                        $cache->set($_, $context->{$_});
190
                    }
191
                }
192
193
                $ret;
157
            });
194
            });
158
        }
195
        }
159
    }
196
    }
(-)a/Koha/Handler/Plack/CGI.pm (-1 / +1 lines)
Lines 73-79 use Plack::App::CGIBin; Link Here
73
73
74
use parent "Koha::Handler::Plack";
74
use parent "Koha::Handler::Plack";
75
75
76
use C4::Context;
76
use C4::Context ":no_config";
77
77
78
=head1 CLASS METHODS
78
=head1 CLASS METHODS
79
79
(-)a/Koha/MetaSearcher.pm (-2 / +2 lines)
Lines 25-31 use C4::Charset qw( MarcToUTF8Record ); Link Here
25
use C4::Search qw(); # Purely for new_record_from_zebra
25
use C4::Search qw(); # Purely for new_record_from_zebra
26
use DBIx::Class::ResultClass::HashRefInflator;
26
use DBIx::Class::ResultClass::HashRefInflator;
27
use IO::Select;
27
use IO::Select;
28
use Koha::Caches;
28
use C4::Context;
29
use Koha::Database;
29
use Koha::Database;
30
use Koha::MetadataRecord;
30
use Koha::MetadataRecord;
31
use MARC::File::XML;
31
use MARC::File::XML;
Lines 91-97 sub search { Link Here
91
91
92
    my $resultset_expiry = 300;
92
    my $resultset_expiry = 300;
93
93
94
    my $cache = Koha::Caches->get_instance();
94
    my $cache = C4::Context->cache;
95
    my $schema = Koha::Database->new->schema;
95
    my $schema = Koha::Database->new->schema;
96
    my $stats = {
96
    my $stats = {
97
        num_fetched => {
97
        num_fetched => {
(-)a/Koha/Template/Plugin/Cache.pm (-3 / +1 lines)
Lines 21-27 use strict; Link Here
21
use warnings;
21
use warnings;
22
use base qw( Template::Plugin );
22
use base qw( Template::Plugin );
23
use Template::Plugin;
23
use Template::Plugin;
24
use C4::Context;
25
24
26
#------------------------------------------------------------------------
25
#------------------------------------------------------------------------
27
# new(\%options)
26
# new(\%options)
Lines 34-41 sub new { Link Here
34
        $cache = delete $params->{cache};
33
        $cache = delete $params->{cache};
35
    }
34
    }
36
    else {
35
    else {
37
        require Koha::Cache;
36
        $cache = $context->cache;
38
        $cache = Koha::Caches->get_instance();
39
    }
37
    }
40
    my $self = bless {
38
    my $self = bless {
41
        CACHE   => $cache,
39
        CACHE   => $cache,
(-)a/about.pl (-2 / +1 lines)
Lines 36-42 use C4::Installer; Link Here
36
use Koha;
36
use Koha;
37
use Koha::Acquisition::Currencies;
37
use Koha::Acquisition::Currencies;
38
use Koha::Patrons;
38
use Koha::Patrons;
39
use Koha::Caches;
40
use Koha::Config::SysPrefs;
39
use Koha::Config::SysPrefs;
41
use C4::Members::Statistics;
40
use C4::Members::Statistics;
42
41
Lines 75-81 if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { Link Here
75
my $memcached_servers   = $ENV{MEMCACHED_SERVERS} || C4::Context->config('memcached_servers');
74
my $memcached_servers   = $ENV{MEMCACHED_SERVERS} || C4::Context->config('memcached_servers');
76
my $memcached_namespace = $ENV{MEMCACHED_NAMESPACE} || C4::Context->config('memcached_namespace') // 'koha';
75
my $memcached_namespace = $ENV{MEMCACHED_NAMESPACE} || C4::Context->config('memcached_namespace') // 'koha';
77
76
78
my $cache = Koha::Caches->get_instance;
77
my $cache = C4::Context->cache;
79
my $effective_caching_method = ref($cache->cache);
78
my $effective_caching_method = ref($cache->cache);
80
# Memcached may have been running when plack has been initialized but could have been stopped since
79
# Memcached may have been running when plack has been initialized but could have been stopped since
81
# FIXME What are the consequences of that??
80
# FIXME What are the consequences of that??
(-)a/admin/biblio_framework.pl (-2 / +1 lines)
Lines 26-37 use C4::Output; Link Here
26
use Koha::Biblios;
26
use Koha::Biblios;
27
use Koha::BiblioFramework;
27
use Koha::BiblioFramework;
28
use Koha::BiblioFrameworks;
28
use Koha::BiblioFrameworks;
29
use Koha::Caches;
30
29
31
my $input         = new CGI;
30
my $input         = new CGI;
32
my $frameworkcode = $input->param('frameworkcode') || q||;
31
my $frameworkcode = $input->param('frameworkcode') || q||;
33
my $op            = $input->param('op') || q|list|;
32
my $op            = $input->param('op') || q|list|;
34
my $cache         = Koha::Caches->get_instance();
33
my $cache         = C4::Context->cache;
35
my @messages;
34
my @messages;
36
35
37
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
36
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
(-)a/admin/koha2marclinks.pl (-1 / +1 lines)
Lines 59-65 else { Link Here
59
}
59
}
60
60
61
my $dbh = C4::Context->dbh;
61
my $dbh = C4::Context->dbh;
62
my $cache = Koha::Caches->get_instance();
62
my $cache = C4::Context->cache;
63
63
64
################## ADD_FORM ##################################
64
################## ADD_FORM ##################################
65
# called by default. Used to create form to add or  modify a record
65
# called by default. Used to create form to add or  modify a record
(-)a/admin/marc_subfields_structure.pl (-1 / +1 lines)
Lines 78-84 my ( $template, $borrowernumber, $cookie ) = get_template_and_user( Link Here
78
        debug           => 1,
78
        debug           => 1,
79
    }
79
    }
80
);
80
);
81
my $cache = Koha::Caches->get_instance();
81
my $cache = C4::Context->cache;
82
82
83
my $op       = $input->param('op') || "";
83
my $op       = $input->param('op') || "";
84
$tagfield =~ s/\,//g;
84
$tagfield =~ s/\,//g;
(-)a/admin/marctagstructure.pl (-6 / +1 lines)
Lines 25-35 use C4::Auth; Link Here
25
use C4::Koha;
25
use C4::Koha;
26
use C4::Context;
26
use C4::Context;
27
use C4::Output;
27
use C4::Output;
28
use C4::Context;
29
30
use Koha::Caches;
31
use Koha::AuthorisedValues;
32
use Koha::BiblioFrameworks;
33
28
34
# retrieve parameters
29
# retrieve parameters
35
my $input = new CGI;
30
my $input = new CGI;
Lines 46-52 my $pagesize = 20; Link Here
46
my $script_name = "/cgi-bin/koha/admin/marctagstructure.pl";
41
my $script_name = "/cgi-bin/koha/admin/marctagstructure.pl";
47
42
48
my $dbh = C4::Context->dbh;
43
my $dbh = C4::Context->dbh;
49
my $cache = Koha::Caches->get_instance();
44
my $cache = C4::Context->cache;
50
45
51
# open template
46
# open template
52
my ($template, $loggedinuser, $cookie)
47
my ($template, $loggedinuser, $cookie)
(-)a/opac/svc/report (-3 / +2 lines)
Lines 23-34 Link Here
23
23
24
use Modern::Perl;
24
use Modern::Perl;
25
25
26
use C4::Context;
26
use C4::Reports::Guided;
27
use C4::Reports::Guided;
27
use JSON;
28
use JSON;
28
use CGI qw ( -utf8 );
29
use CGI qw ( -utf8 );
29
30
30
use Koha::Caches;
31
32
my $query       = CGI->new();
31
my $query       = CGI->new();
33
my $report_id   = $query->param('id');
32
my $report_id   = $query->param('id');
34
my $report_name = $query->param('name');
33
my $report_name = $query->param('name');
Lines 41-47 die "Sorry this report is not public\n" unless $report_rec->{public}; Link Here
41
40
42
my @sql_params  = $query->param('sql_params');
41
my @sql_params  = $query->param('sql_params');
43
42
44
my $cache = Koha::Caches->get_instance();
43
my $cache = C4::Context->cache;
45
my $cache_active = $cache->is_cache_active;
44
my $cache_active = $cache->is_cache_active;
46
my ($cache_key, $json_text);
45
my ($cache_key, $json_text);
47
if ($cache_active) {
46
if ($cache_active) {
(-)a/reports/guided_reports.pl (-2 / +1 lines)
Lines 29-35 use C4::Auth qw/:DEFAULT get_session/; Link Here
29
use C4::Output;
29
use C4::Output;
30
use C4::Debug;
30
use C4::Debug;
31
use C4::Context;
31
use C4::Context;
32
use Koha::Caches;
33
use C4::Log;
32
use C4::Log;
34
use Koha::DateUtils qw/dt_from_string output_pref/;
33
use Koha::DateUtils qw/dt_from_string output_pref/;
35
use Koha::AuthorisedValue;
34
use Koha::AuthorisedValue;
Lines 49-55 Script to control the guided report creation Link Here
49
=cut
48
=cut
50
49
51
my $input = new CGI;
50
my $input = new CGI;
52
my $usecache = Koha::Caches->get_instance->memcached_cache;
51
my $usecache = C4::Context->cache->memcached_cache;
53
52
54
my $phase = $input->param('phase') // '';
53
my $phase = $input->param('phase') // '';
55
my $flagsrequired;
54
my $flagsrequired;
(-)a/svc/report (-2 / +2 lines)
Lines 25-31 use C4::Reports::Guided; Link Here
25
use JSON;
25
use JSON;
26
use CGI qw ( -utf8 );
26
use CGI qw ( -utf8 );
27
27
28
use Koha::Caches;
28
use C4::Context;
29
29
30
30
31
my $query  = CGI->new();
31
my $query  = CGI->new();
Lines 48-54 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
48
    }
48
    }
49
);
49
);
50
50
51
my $cache = Koha::Caches->get_instance();
51
my $cache = C4::Context->cache;
52
my $cache_active = $cache->is_cache_active;
52
my $cache_active = $cache->is_cache_active;
53
my ($cache_key, $json_text);
53
my ($cache_key, $json_text);
54
if ($cache_active) {
54
if ($cache_active) {
(-)a/t/Calendar.t (-2 / +2 lines)
Lines 22-28 use Test::MockModule; Link Here
22
22
23
use DateTime;
23
use DateTime;
24
use DateTime::Duration;
24
use DateTime::Duration;
25
use Koha::Caches;
25
use C4::Context;
26
use Koha::DateUtils;
26
use Koha::DateUtils;
27
27
28
use Module::Load::Conditional qw/check_install/;
28
use Module::Load::Conditional qw/check_install/;
Lines 89-95 fixtures_ok [ Link Here
89
      ],
89
      ],
90
], "add fixtures";
90
], "add fixtures";
91
91
92
my $cache = Koha::Caches->get_instance();
92
my $cache = C4::Context->cache;
93
$cache->clear_from_cache( 'single_holidays') ;
93
$cache->clear_from_cache( 'single_holidays') ;
94
94
95
# 'MPL' branch is arbitrary, is not used at all but is needed for initialization
95
# 'MPL' branch is arbitrary, is not used at all but is needed for initialization
(-)a/t/Context.t (-1 / +27 lines)
Lines 2-8 Link Here
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use DBI;
4
use DBI;
5
use Test::More tests => 26;
5
use Test::More tests => 29;
6
use Test::MockModule;
6
use Test::MockModule;
7
7
8
BEGIN {
8
BEGIN {
Lines 62-64 is(C4::Context->interface, 'opac', 'interface still opac'); Link Here
62
#Bug 14751
62
#Bug 14751
63
is( C4::Context->interface( 'SiP' ), 'sip', 'interface SiP' );
63
is( C4::Context->interface( 'SiP' ), 'sip', 'interface SiP' );
64
is( C4::Context->interface( 'COMMANDLINE' ), 'commandline', 'interface commandline uc' );
64
is( C4::Context->interface( 'COMMANDLINE' ), 'commandline', 'interface commandline uc' );
65
66
my $DUMMY_KOHA_CONF = "<yazgfs><config><kohasite>TEST</kohasite></config></yazgfs>";
67
my $ctx_a = C4::Context->new($DUMMY_KOHA_CONF, "a");
68
my $ctx_b = C4::Context->new($DUMMY_KOHA_CONF, "b");
69
my $cache_key = "test_C4::Context";
70
71
SKIP: {
72
    skip "No cache", 3 unless $ctx_a->cache->is_cache_active && $ctx_b->cache->is_cache_active;
73
74
    # Light warm up
75
    C4::Context->cache->set_in_cache($cache_key, 'c');
76
    $ctx_a->cache->set_in_cache($cache_key, 'a');
77
    $ctx_b->cache->set_in_cache($cache_key, 'b');
78
    is(C4::Context->cache->get_from_cache($cache_key), 'c', "Correct default cache value");
79
    is($ctx_a->cache->get_from_cache($cache_key), 'a', "Correct cache 'a' value");
80
    is($ctx_b->cache->get_from_cache($cache_key), 'b', "Correct cache 'b' value");
81
82
    # A bit more extravagant
83
    # Cannot run atm, fails due to no database in config
84
#   $ctx_a->run_within_context( sub {
85
#       $ctx_b->cache->set_in_cache($cache_key, 'bb');
86
#       C4::Context->cache->set_in_cache($cache_key, 'aa');
87
#   } );
88
#   is($ctx_a->cache->get_from_cache($cache_key), 'aa', "Correct cache 'a' value");
89
#   is($ctx_b->cache->get_from_cache($cache_key), 'bb', "Correct cache 'b' value");
90
}
(-)a/t/Koha_Template_Plugin_Cache.t (-1 / +3 lines)
Lines 1-6 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
use Test::More tests => 2;
2
use Test::More tests => 2;
3
3
4
use C4::Context;
5
4
use_ok('Koha::Template::Plugin::Cache');
6
use_ok('Koha::Template::Plugin::Cache');
5
7
6
ok(my $cache = Koha::Template::Plugin::Cache->new());
8
ok(my $cache = Koha::Template::Plugin::Cache->new(C4::Context->current));
(-)a/t/db_dependent/Context.t (-7 / +1 lines)
Lines 12-25 use Koha::Database; Link Here
12
12
13
BEGIN {
13
BEGIN {
14
    $debug = $ENV{DEBUG} || 0;
14
    $debug = $ENV{DEBUG} || 0;
15
16
    # Note: The overall number of tests may vary by configuration.
17
    # First we need to check your environmental variables
18
    for (qw(KOHA_CONF PERL5LIB)) {
19
        ok( $ret = $ENV{$_}, "ENV{$_} = $ret" );
20
    }
21
    use_ok('C4::Context');
22
}
15
}
16
use_ok('C4::Context');
23
17
24
ok($dbh = C4::Context->dbh(), 'Getting dbh from C4::Context');
18
ok($dbh = C4::Context->dbh(), 'Getting dbh from C4::Context');
25
19
(-)a/t/db_dependent/Filter_MARC_ViewPolicy.t (-3 / +2 lines)
Lines 30-36 use MARC::Record; Link Here
30
use MARC::Field;
30
use MARC::Field;
31
use C4::Context;
31
use C4::Context;
32
use C4::Biblio;
32
use C4::Biblio;
33
use Koha::Caches;
34
use Koha::Database;
33
use Koha::Database;
35
34
36
BEGIN {
35
BEGIN {
Lines 66-72 sub run_hiding_tests { Link Here
66
65
67
        $sth->execute($hidden_value);
66
        $sth->execute($hidden_value);
68
67
69
        my $cache = Koha::Caches->get_instance();
68
        my $cache = C4::Context->cache;
70
        $cache->flush_all();    # easy way to ensure DB is queried again.
69
        $cache->flush_all();    # easy way to ensure DB is queried again.
71
70
72
        my $processor = Koha::RecordProcessor->new(
71
        my $processor = Koha::RecordProcessor->new(
Lines 138-144 sub run_hiding_tests { Link Here
138
137
139
    $sth->execute(-1); # -1 is visible in opac and intranet.
138
    $sth->execute(-1); # -1 is visible in opac and intranet.
140
139
141
    my $cache = Koha::Caches->get_instance();
140
    my $cache = C4::Context->cache;
142
    $cache->flush_all();    # easy way to ensure DB is queried again.
141
    $cache->flush_all();    # easy way to ensure DB is queried again.
143
142
144
    my $shouldhidemarc = Koha::Filter::MARC::ViewPolicy->should_hide_marc(
143
    my $shouldhidemarc = Koha::Filter::MARC::ViewPolicy->should_hide_marc(
(-)a/t/db_dependent/Items.t (-2 / +3 lines)
Lines 19-24 Link Here
19
use Modern::Perl;
19
use Modern::Perl;
20
20
21
use MARC::Record;
21
use MARC::Record;
22
use C4::Context;
22
use C4::Biblio;
23
use C4::Biblio;
23
use Koha::Database;
24
use Koha::Database;
24
use Koha::Library;
25
use Koha::Library;
Lines 410-416 subtest 'SearchItems test' => sub { Link Here
410
    $dbh->do('INSERT INTO marc_subfield_structure (tagfield, tagsubfield, frameworkcode) VALUES (?, "z", ?)', undef, $itemfield, $frameworkcode);
411
    $dbh->do('INSERT INTO marc_subfield_structure (tagfield, tagsubfield, frameworkcode) VALUES (?, "z", ?)', undef, $itemfield, $frameworkcode);
411
412
412
    # Clear cache
413
    # Clear cache
413
    my $cache = Koha::Caches->get_instance();
414
    my $cache = C4::Context->cache;
414
    $cache->clear_from_cache("MarcStructure-0-$frameworkcode");
415
    $cache->clear_from_cache("MarcStructure-0-$frameworkcode");
415
    $cache->clear_from_cache("MarcStructure-1-$frameworkcode");
416
    $cache->clear_from_cache("MarcStructure-1-$frameworkcode");
416
    $cache->clear_from_cache("default_value_for_mod_marc-$frameworkcode");
417
    $cache->clear_from_cache("default_value_for_mod_marc-$frameworkcode");
Lines 710-716 subtest 'C4::Items::_build_default_values_for_mod_marc' => sub { Link Here
710
    |, undef, $framework->{frameworkcode} );
711
    |, undef, $framework->{frameworkcode} );
711
712
712
    # And make sure the caches are cleared
713
    # And make sure the caches are cleared
713
    my $cache = Koha::Caches->get_instance();
714
    my $cache = C4::Context->cache;
714
    $cache->clear_from_cache("MarcStructure-0-" . $framework->{frameworkcode});
715
    $cache->clear_from_cache("MarcStructure-0-" . $framework->{frameworkcode});
715
    $cache->clear_from_cache("MarcStructure-1-" . $framework->{frameworkcode});
716
    $cache->clear_from_cache("MarcStructure-1-" . $framework->{frameworkcode});
716
    $cache->clear_from_cache("default_value_for_mod_marc-" . $framework->{frameworkcode});
717
    $cache->clear_from_cache("default_value_for_mod_marc-" . $framework->{frameworkcode});
(-)a/tools/newHolidays.pl (-3 / +2 lines)
Lines 10-16 use CGI qw ( -utf8 ); Link Here
10
use C4::Auth;
10
use C4::Auth;
11
use C4::Output;
11
use C4::Output;
12
12
13
use Koha::Caches;
13
use C4::Context;
14
14
15
use C4::Calendar;
15
use C4::Calendar;
16
use DateTime;
16
use DateTime;
Lines 128-133 sub add_holiday { Link Here
128
        }
128
        }
129
    }
129
    }
130
    # we updated the single_holidays table, so wipe its cache
130
    # we updated the single_holidays table, so wipe its cache
131
    my $cache = Koha::Caches->get_instance();
131
    my $cache = C4::Context->cache;
132
    $cache->clear_from_cache( 'single_holidays') ;
132
    $cache->clear_from_cache( 'single_holidays') ;
133
}
133
}
134
- 

Return to bug 15562