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

(-)a/C4/Biblio.pm (-2 / +2 lines)
Lines 37-44 use C4::ClassSource; Link Here
37
use C4::Charset;
37
use C4::Charset;
38
use C4::Linker;
38
use C4::Linker;
39
use C4::OAI::Sets;
39
use C4::OAI::Sets;
40
use C4::Context;
40
41
41
use Koha::Cache;
42
use Koha::Authority::Types;
42
use Koha::Authority::Types;
43
43
44
use vars qw($VERSION @ISA @EXPORT);
44
use vars qw($VERSION @ISA @EXPORT);
Lines 1096-1102 sub GetMarcStructure { Link Here
1096
    $frameworkcode = "" unless $frameworkcode;
1096
    $frameworkcode = "" unless $frameworkcode;
1097
1097
1098
    $forlibrarian = $forlibrarian ? 1 : 0;
1098
    $forlibrarian = $forlibrarian ? 1 : 0;
1099
    my $cache = Koha::Cache->get_instance();
1099
    my $cache = C4::Context->cache;
1100
    my $cache_key = "MarcStructure-$forlibrarian-$frameworkcode";
1100
    my $cache_key = "MarcStructure-$forlibrarian-$frameworkcode";
1101
    my $cached = $cache->get_from_cache($cache_key);
1101
    my $cached = $cache->get_from_cache($cache_key);
1102
    return $cached if $cached;
1102
    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::Cache;
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::Cache->get_instance();
278
    my $cache = C4::Context->cache;
280
    $cache->clear_from_cache( 'single_holidays') ;
279
    $cache->clear_from_cache( 'single_holidays') ;
281
280
282
    return $self;
281
    return $self;
Lines 320-326 sub insert_exception_holiday { Link Here
320
    $self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description};
319
    $self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description};
321
320
322
    # changed the 'single_holidays' table, lets force/reset its cache
321
    # changed the 'single_holidays' table, lets force/reset its cache
323
    my $cache = Koha::Cache->get_instance();
322
    my $cache = C4::Context->cache;
324
    $cache->clear_from_cache( 'single_holidays') ;
323
    $cache->clear_from_cache( 'single_holidays') ;
325
324
326
    return $self;
325
    return $self;
Lines 420-426 UPDATE special_holidays SET title = ?, description = ? Link Here
420
    $self->{'single_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description};
419
    $self->{'single_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description};
421
420
422
    # changed the 'single_holidays' table, lets force/reset its cache
421
    # changed the 'single_holidays' table, lets force/reset its cache
423
    my $cache = Koha::Cache->get_instance();
422
    my $cache = C4::Context->cache;
424
    $cache->clear_from_cache( 'single_holidays') ;
423
    $cache->clear_from_cache( 'single_holidays') ;
425
424
426
    return $self;
425
    return $self;
Lines 462-468 UPDATE special_holidays SET title = ?, description = ? Link Here
462
    $self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description};
461
    $self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description};
463
462
464
    # changed the 'single_holidays' table, lets force/reset its cache
463
    # changed the 'single_holidays' table, lets force/reset its cache
465
    my $cache = Koha::Cache->get_instance();
464
    my $cache = C4::Context->cache;
466
    $cache->clear_from_cache( 'single_holidays') ;
465
    $cache->clear_from_cache( 'single_holidays') ;
467
466
468
    return $self;
467
    return $self;
Lines 542-548 sub delete_holiday { Link Here
542
    }
541
    }
543
542
544
    # changed the 'single_holidays' table, lets force/reset its cache
543
    # changed the 'single_holidays' table, lets force/reset its cache
545
    my $cache = Koha::Cache->get_instance();
544
    my $cache = C4::Context->cache;
546
    $cache->clear_from_cache( 'single_holidays') ;
545
    $cache->clear_from_cache( 'single_holidays') ;
547
546
548
    return $self;
547
    return $self;
Lines 572-578 sub delete_holiday_range { Link Here
572
    $sth->execute($self->{branchcode}, $options{day}, $options{month}, $options{year});
571
    $sth->execute($self->{branchcode}, $options{day}, $options{month}, $options{year});
573
572
574
    # changed the 'single_holidays' table, lets force/reset its cache
573
    # changed the 'single_holidays' table, lets force/reset its cache
575
    my $cache = Koha::Cache->get_instance();
574
    my $cache = C4::Context->cache;
576
    $cache->clear_from_cache( 'single_holidays') ;
575
    $cache->clear_from_cache( 'single_holidays') ;
577
576
578
}
577
}
Lines 625-631 sub delete_exception_holiday_range { Link Here
625
    $sth->execute($self->{branchcode}, $options{day}, $options{month}, $options{year});
624
    $sth->execute($self->{branchcode}, $options{day}, $options{month}, $options{year});
626
625
627
    # changed the 'single_holidays' table, lets force/reset its cache
626
    # changed the 'single_holidays' table, lets force/reset its cache
628
    my $cache = Koha::Cache->get_instance();
627
    my $cache = C4::Context->cache;
629
    $cache->clear_from_cache( 'single_holidays') ;
628
    $cache->clear_from_cache( 'single_holidays') ;
630
}
629
}
631
630
(-)a/C4/Context.pm (-40 / +71 lines)
Lines 18-24 package C4::Context; Link Here
18
18
19
use strict;
19
use strict;
20
use warnings;
20
use warnings;
21
use vars qw($VERSION $AUTOLOAD $context @context_stack $servers $memcached $ismemcached);
21
use vars qw($VERSION $AUTOLOAD $context @context_stack $memcached_servers);
22
BEGIN {
22
BEGIN {
23
	if ($ENV{'HTTP_USER_AGENT'})	{
23
	if ($ENV{'HTTP_USER_AGENT'})	{
24
		require CGI::Carp;
24
		require CGI::Carp;
Lines 79-98 BEGIN { Link Here
79
    }  	# else there is no browser to send fatals to!
79
    }  	# else there is no browser to send fatals to!
80
80
81
    # Check if there are memcached servers set
81
    # Check if there are memcached servers set
82
    $servers = $ENV{'MEMCACHED_SERVERS'};
82
    $memcached_servers = $ENV{'MEMCACHED_SERVERS'};
83
    if ($servers) {
83
    # Load required libraries and create the memcached object
84
        # Load required libraries and create the memcached object
84
    require Cache::Memcached if $memcached_servers;
85
        require Cache::Memcached;
86
        $memcached = Cache::Memcached->new({
87
        servers => [ $servers ],
88
        debug   => 0,
89
        compress_threshold => 10_000,
90
        expire_time => 600,
91
        namespace => $ENV{'MEMCACHED_NAMESPACE'} || 'koha'
92
    });
93
        # Verify memcached available (set a variable and test the output)
94
    $ismemcached = $memcached->set('ismemcached','1');
95
    }
96
85
97
    $VERSION = '3.07.00.049';
86
    $VERSION = '3.07.00.049';
98
}
87
}
Lines 109-114 use Carp; Link Here
109
use C4::Boolean;
98
use C4::Boolean;
110
use C4::Debug;
99
use C4::Debug;
111
use Koha;
100
use Koha;
101
use Koha::Cache;
112
use Koha::Config::SysPrefs;
102
use Koha::Config::SysPrefs;
113
103
114
=head1 NAME
104
=head1 NAME
Lines 209-237 sub current { Link Here
209
    return $context;
199
    return $context;
210
}
200
}
211
201
212
=head2 ismemcached
202
sub _new_memcached {
203
    my $namespace = shift or die "No memcached namespace";
204
205
    return unless $memcached_servers;
206
    return Cache::Memcached->new({
207
        servers => [ $memcached_servers ],
208
        debug   => 0,
209
        compress_threshold => 10_000,
210
        expire_time => 600,
211
        namespace => $namespace
212
    });
213
}
214
# Verify memcached available (test the output)
215
sub _ping_memcached {
216
    my $memcached = shift or croak "No memcached";
217
218
    return $memcached->set('ismemcached','1');
219
}
220
221
=head2 cache
213
222
214
Returns the value of the $ismemcached variable (0/1)
223
Returns the cache object or undef
215
224
216
=cut
225
=cut
217
226
218
sub ismemcached {
227
sub cache {
219
    return $ismemcached;
228
    my $self = shift;
229
230
    $self = $context unless ref ($self);
231
    return unless $self;
232
233
    return $self->{cache} ||= Koha::Cache->new();
220
}
234
}
221
235
222
=head2 memcached
236
=head2 memcached
223
237
224
If $ismemcached is true, returns the $memcache variable.
238
Returns the memcached object or undef
225
Returns undef otherwise
239
240
=head2 ismemcached
226
241
227
=cut
242
=cut
228
243
229
sub memcached {
244
sub memcached {
230
    if ($ismemcached) {
245
    my $self = shift;
231
      return $memcached;
246
232
    } else {
247
    $self = $context unless ref ($self);
233
      return;
248
    return unless $self;
234
    }
249
250
    my $memcached = $self->{memcached} or return;
251
    return _ping_memcached($memcached) ? $memcached : undef;
252
}
253
254
sub ismemcached {
255
    my $self = shift;
256
    return $self->memcached;
235
}
257
}
236
258
237
sub db_driver {
259
sub db_driver {
Lines 273-282 sub import { Link Here
273
    # default context already exists?
295
    # default context already exists?
274
    return if $context;
296
    return if $context;
275
297
276
    if ($ismemcached) {
298
    return if $config_file && $config_file eq ":no_config";
299
300
    my $memcached = _new_memcached($ENV{'MEMCACHED_NAMESPACE'} || 'koha');
301
    if ($memcached) {
277
        # retrieve from memcached
302
        # retrieve from memcached
278
        if (my $self = $memcached->get('kohaconf')) {
303
        if ($context = $memcached->get('kohaconf')) {
279
            $context = $self;
304
            $context->{memcached} = $memcached;
280
            return;
305
            return;
281
        }
306
        }
282
    }
307
    }
Lines 303-317 sub import { Link Here
303
    }
328
    }
304
329
305
    # no ? so load it!
330
    # no ? so load it!
306
    return if $config_file && $config_file eq ":no_config";
331
    $context = $pkg->new($config_file) or return;
307
    my $new_ctx = __PACKAGE__->new($config_file);
332
    if ( $memcached && _ping_memcached($memcached) ) {
308
    return unless $new_ctx;
333
        $context->{memcached} = $memcached;
309
334
        $memcached->set('kohaconf',$context);
310
    # if successfully loaded, use it by default
311
    $context = $new_ctx;
312
313
    if ($ismemcached) {
314
      $memcached->set('kohaconf',$new_ctx);
315
    }
335
    }
316
}
336
}
317
337
Lines 354-359 that, use C<&set_context>. Link Here
354
sub new {
374
sub new {
355
    my $class = shift;
375
    my $class = shift;
356
    my $conf_fname = shift or croak "No conf";
376
    my $conf_fname = shift or croak "No conf";
377
    my $memcached_namespace = shift;
378
    my $cache = shift;
357
379
358
    my $self = XMLin(
380
    my $self = XMLin(
359
        $conf_fname,
381
        $conf_fname,
Lines 365-370 sub new { Link Here
365
      unless ref($self) && $self->{"config"};
387
      unless ref($self) && $self->{"config"};
366
388
367
    $self->{"config_file"} = "$conf_fname";
389
    $self->{"config_file"} = "$conf_fname";
390
    if ($memcached_namespace) {
391
        my $memcached = $context->{memcached};
392
        $self->{memcached} = $memcached && $memcached->{namespace} eq $memcached_namespace
393
            ? $memcached
394
            : _new_memcached($memcached_namespace);
395
        # Koha::Cache is far too complex to try to make any savings
396
        $cache ||= Koha::Cache->new( {namespace => $memcached_namespace} );
397
    }
398
    $self->{cache} = $cache;
368
399
369
    $self->{"Zconn"} = undef;    # Zebra Connections
400
    $self->{"Zconn"} = undef;    # Zebra Connections
370
    $self->{"marcfromkohafield"} = undef; # the hash with relations between koha table fields and MARC field/subfield
401
    $self->{"marcfromkohafield"} = undef; # the hash with relations between koha table fields and MARC field/subfield
Lines 425-432 sub set_context Link Here
425
        $schema = $self->{schema} ||= Koha::Database->new_schema($self);
456
        $schema = $self->{schema} ||= Koha::Database->new_schema($self);
426
    }
457
    }
427
458
428
    # Save the old context, if any, on the stack
459
    # Save the old context on the stack
429
    push @context_stack, $context if defined($context);
460
    push @context_stack, $context;
430
461
431
    # Set the new context
462
    # Set the new context
432
    $context = $new_context;
463
    $context = $new_context;
(-)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::Cache;
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 98-106 sub GetOverDriveToken { Link Here
98
98
99
    return unless ( $key && $secret ) ;
99
    return unless ( $key && $secret ) ;
100
100
101
    my $cache;
101
    my $cache = C4::Context->cache;
102
103
    eval { $cache = Koha::Cache->get_instance() };
104
102
105
    my $token;
103
    my $token;
106
    $cache and $token = $cache->get_from_cache( "overdrive_token" ) and return $token;
104
    $cache and $token = $cache->get_from_cache( "overdrive_token" ) and return $token;
(-)a/C4/Koha.pm (-2 / +1 lines)
Lines 25-31 use strict; Link Here
25
25
26
use C4::Context;
26
use C4::Context;
27
use C4::Branch; # Can be removed?
27
use C4::Branch; # Can be removed?
28
use Koha::Cache;
29
use Koha::DateUtils qw(dt_from_string);
28
use Koha::DateUtils qw(dt_from_string);
30
use Koha::Libraries;
29
use Koha::Libraries;
31
use DateTime::Format::MySQL;
30
use DateTime::Format::MySQL;
Lines 1167-1173 sub GetAuthorisedValues { Link Here
1167
    my $selected_key = defined($selected) ? $selected : '';
1166
    my $selected_key = defined($selected) ? $selected : '';
1168
    my $cache_key =
1167
    my $cache_key =
1169
      "AuthorisedValues-$category-$selected_key-$opac-$branch_limit";
1168
      "AuthorisedValues-$category-$selected_key-$opac-$branch_limit";
1170
    my $cache  = Koha::Cache->get_instance();
1169
    my $cache  = C4::Context->cache;
1171
    my $result = $cache->get_from_cache($cache_key);
1170
    my $result = $cache->get_from_cache($cache_key);
1172
    return $result if $result;
1171
    return $result if $result;
1173
1172
(-)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::Cache;
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::Cache->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 (-17 lines)
Lines 46-68 use base qw(Class::Accessor); Link Here
46
__PACKAGE__->mk_ro_accessors(
46
__PACKAGE__->mk_ro_accessors(
47
    qw( cache memcached_cache fastmmap_cache memory_cache ));
47
    qw( cache memcached_cache fastmmap_cache memory_cache ));
48
48
49
=head2 get_instance
50
51
    my $cache = Koha::Cache->get_instance();
52
53
This gets a shared instance of the cache, set up in a very default way. This is
54
the recommended way to fetch a cache object. If possible, it'll be
55
persistent across multiple instances.
56
57
=cut
58
59
our $singleton_cache;
60
sub get_instance {
61
    my ($class) = @_;
62
    $singleton_cache = $class->new() unless $singleton_cache;
63
    return $singleton_cache;
64
}
65
66
=head2 new
49
=head2 new
67
50
68
Create a new Koha::Cache object. This is required for all cache-related functionality.
51
Create a new Koha::Cache object. This is required for all cache-related functionality.
(-)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::Cache;
11
use Carp;
10
use Carp;
12
11
13
sub new {
12
sub new {
Lines 57-63 sub _init { Link Here
57
# lists breaks persistance engines.  As of 2013-12-10, the RM
56
# lists breaks persistance engines.  As of 2013-12-10, the RM
58
# is allowing this with the expectation that prior to release of
57
# is allowing this with the expectation that prior to release of
59
# 3.16, bug 8089 will be fixed and we can switch the caching over
58
# 3.16, bug 8089 will be fixed and we can switch the caching over
60
# to Koha::Cache.
59
# to external cache
61
60
62
our $exception_holidays;
61
our $exception_holidays;
63
62
Lines 92-98 sub exception_holidays { Link Here
92
sub single_holidays {
91
sub single_holidays {
93
    my ( $self, $date ) = @_;
92
    my ( $self, $date ) = @_;
94
    my $branchcode = $self->{branchcode};
93
    my $branchcode = $self->{branchcode};
95
    my $cache           = Koha::Cache->get_instance();
94
    my $cache           = C4::Context->cache;
96
    my $single_holidays = $cache->get_from_cache('single_holidays');
95
    my $single_holidays = $cache->get_from_cache('single_holidays');
97
96
98
    # $single_holidays looks like:
97
    # $single_holidays looks like:
(-)a/Koha/Template/Plugin/Cache.pm (-3 / +1 lines)
Lines 22-28 use warnings; Link Here
22
use vars qw( $VERSION );
22
use vars qw( $VERSION );
23
use base qw( Template::Plugin );
23
use base qw( Template::Plugin );
24
use Template::Plugin;
24
use Template::Plugin;
25
use C4::Context;
26
$VERSION = '0.01';
25
$VERSION = '0.01';
27
26
28
#------------------------------------------------------------------------
27
#------------------------------------------------------------------------
Lines 36-43 sub new { Link Here
36
        $cache = delete $params->{cache};
35
        $cache = delete $params->{cache};
37
    }
36
    }
38
    else {
37
    else {
39
        require Koha::Cache;
38
        $cache = $context->cache;
40
        $cache = Koha::Cache->get_instance();
41
    }
39
    }
42
    my $self = bless {
40
    my $self = bless {
43
        CACHE   => $cache,
41
        CACHE   => $cache,
(-)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::Cache;
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::Cache->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::Cache->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::Cache->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 (-4 / +1 lines)
Lines 25-33 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::Cache;
31
28
32
# retrieve parameters
29
# retrieve parameters
33
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";
43
my $script_name = "/cgi-bin/koha/admin/marctagstructure.pl";
47
44
48
my $dbh = C4::Context->dbh;
45
my $dbh = C4::Context->dbh;
49
my $cache = Koha::Cache->get_instance();
46
my $cache = C4::Context->cache;
50
47
51
# open template
48
# open template
52
my ($template, $loggedinuser, $cookie)
49
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::Cache;
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::Cache->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/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::Cache;
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::Cache->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/Cache.t (-2 / +2 lines)
Lines 31-37 SKIP: { Link Here
31
    # Set a special namespace for testing, to avoid breaking
31
    # Set a special namespace for testing, to avoid breaking
32
    # if test is run with a different user than Apache's.
32
    # if test is run with a different user than Apache's.
33
    $ENV{ MEMCACHED_NAMESPACE } = 'unit_tests';
33
    $ENV{ MEMCACHED_NAMESPACE } = 'unit_tests';
34
    my $cache = Koha::Cache->get_instance();
34
    my $cache = C4::Context->cache;
35
35
36
    skip "Cache not enabled", 28
36
    skip "Cache not enabled", 28
37
      unless ( $cache->is_cache_active() && defined $cache );
37
      unless ( $cache->is_cache_active() && defined $cache );
Lines 167-173 SKIP: { Link Here
167
END {
167
END {
168
  SKIP: {
168
  SKIP: {
169
        $ENV{ MEMCACHED_NAMESPACE } = 'unit_tests';
169
        $ENV{ MEMCACHED_NAMESPACE } = 'unit_tests';
170
        my $cache = Koha::Cache->get_instance();
170
        my $cache = C4::Context->cache;
171
        skip "Cache not enabled", 1
171
        skip "Cache not enabled", 1
172
          unless ( $cache->is_cache_active() );
172
          unless ( $cache->is_cache_active() );
173
        is( $destructorcount, 1, 'Destructor run exactly once' );
173
        is( $destructorcount, 1, 'Destructor run exactly once' );
(-)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::Cache;
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 88-94 fixtures_ok [ Link Here
88
      ],
88
      ],
89
], "add fixtures";
89
], "add fixtures";
90
90
91
my $cache = Koha::Cache->get_instance();
91
my $cache = C4::Context->cache;
92
$cache->clear_from_cache( 'single_holidays') ;
92
$cache->clear_from_cache( 'single_holidays') ;
93
93
94
# 'MPL' branch is arbitrary, is not used at all but is needed for initialization
94
# 'MPL' branch is arbitrary, is not used at all but is needed for initialization
(-)a/t/Context.t (-1 / +1 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 => 24;
5
use Test::More tests => 29;
6
use Test::MockModule;
6
use Test::MockModule;
7
7
8
BEGIN {
8
BEGIN {
(-)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 / +3 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
Lines 98-103 ok($trace_read, 'Retrieved syspref from database'); Link Here
98
$trace_read = q{};
92
$trace_read = q{};
99
93
100
C4::Context->enable_syspref_cache();
94
C4::Context->enable_syspref_cache();
95
C4::Context->preference("SillyPreference");
96
$trace_read = q{};
101
is(C4::Context->preference("SillyPreference"), 'thing3', "Retrieved syspref (value='thing3') successfully from cache");
97
is(C4::Context->preference("SillyPreference"), 'thing3', "Retrieved syspref (value='thing3') successfully from cache");
102
is( $trace_read, q{}, 'Did not retrieve syspref from database');
98
is( $trace_read, q{}, 'Did not retrieve syspref from database');
103
$trace_read = q{};
99
$trace_read = q{};
(-)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::Cache;
13
use C4::Context;
14
14
15
use C4::Calendar;
15
use C4::Calendar;
16
use DateTime;
16
use DateTime;
Lines 129-134 sub add_holiday { Link Here
129
        }
129
        }
130
    }
130
    }
131
    # we updated the single_holidays table, so wipe its cache
131
    # we updated the single_holidays table, so wipe its cache
132
    my $cache = Koha::Cache->get_instance();
132
    my $cache = C4::Context->cache;
133
    $cache->clear_from_cache( 'single_holidays') ;
133
    $cache->clear_from_cache( 'single_holidays') ;
134
}
134
}
135
- 

Return to bug 15562