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

(-)a/C4/Context.pm (-61 / +16 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($AUTOLOAD $context @context_stack $servers $memcached $ismemcached);
21
use vars qw($AUTOLOAD $context @context_stack $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 86-108 BEGIN { Link Here
86
            $CGI::LIST_CONTEXT_WARN = 0;
86
            $CGI::LIST_CONTEXT_WARN = 0;
87
        }
87
        }
88
    }  	# else there is no browser to send fatals to!
88
    }  	# else there is no browser to send fatals to!
89
90
    # Check if there are memcached servers set
91
    $servers = $ENV{'MEMCACHED_SERVERS'};
92
    if ($servers) {
93
        # Load required libraries and create the memcached object
94
        require Cache::Memcached;
95
        $memcached = Cache::Memcached->new({
96
        servers => [ $servers ],
97
        debug   => 0,
98
        compress_threshold => 10_000,
99
        expire_time => 600,
100
        namespace => $ENV{'MEMCACHED_NAMESPACE'} || 'koha'
101
    });
102
        # Verify memcached available (set a variable and test the output)
103
    $ismemcached = $memcached->set('ismemcached','1');
104
    }
105
106
}
89
}
107
90
108
use Encode;
91
use Encode;
Lines 242-279 Returns undef in case of error. Link Here
242
sub read_config_file {		# Pass argument naming config file to read
225
sub read_config_file {		# Pass argument naming config file to read
243
    my $koha = XMLin(shift, keyattr => ['id'], forcearray => ['listen', 'server', 'serverinfo'], suppressempty => '');
226
    my $koha = XMLin(shift, keyattr => ['id'], forcearray => ['listen', 'server', 'serverinfo'], suppressempty => '');
244
227
245
    if ($ismemcached) {
246
      $memcached->set('kohaconf',$koha);
247
    }
248
249
    return $koha;			# Return value: ref-to-hash holding the configuration
228
    return $koha;			# Return value: ref-to-hash holding the configuration
250
}
229
}
251
230
252
=head2 ismemcached
253
254
Returns the value of the $ismemcached variable (0/1)
255
256
=cut
257
258
sub ismemcached {
259
    return $ismemcached;
260
}
261
262
=head2 memcached
263
264
If $ismemcached is true, returns the $memcache variable.
265
Returns undef otherwise
266
267
=cut
268
269
sub memcached {
270
    if ($ismemcached) {
271
      return $memcached;
272
    } else {
273
      return;
274
    }
275
}
276
277
=head2 db_scheme2dbi
231
=head2 db_scheme2dbi
278
232
279
    my $dbd_driver_name = C4::Context::db_schema2dbi($scheme);
233
    my $dbd_driver_name = C4::Context::db_schema2dbi($scheme);
Lines 355-376 sub new { Link Here
355
            return;
309
            return;
356
        }
310
        }
357
    }
311
    }
358
    
312
359
    if ($ismemcached) {
313
    my $conf_cache = Koha::Caches->get_instance('config');
360
        # retrieve from memcached
314
    if ( $conf_cache ) {
361
        $self = $memcached->get('kohaconf');
315
        $self = $conf_cache->get_from_cache('kohaconf');
362
        if (not defined $self) {
316
    }
363
            # not in memcached yet
317
    unless ( %$self ) {
364
            $self = read_config_file($conf_fname);
365
        }
366
    } else {
367
        # non-memcached env, read from file
368
        $self = read_config_file($conf_fname);
318
        $self = read_config_file($conf_fname);
369
    }
319
    }
370
320
    if ( $conf_cache ) {
371
    $self->{"config_file"} = $conf_fname;
321
        # FIXME it may be better to use the memcached servers from the config file
372
    warn "read_config_file($conf_fname) returned undef" if !defined($self->{"config"});
322
        # to cache it
373
    return if !defined($self->{"config"});
323
        $conf_cache->set_in_cache('koha_conf', $self)
324
    }
325
    unless ( exists $self->{config} or defined $self->{config} ) {
326
        warn "read_config_file($conf_fname) returned undef";
327
        return;
328
    }
374
329
375
    $self->{"Zconn"} = undef;    # Zebra Connections
330
    $self->{"Zconn"} = undef;    # Zebra Connections
376
    $self->{"marcfromkohafield"} = undef; # the hash with relations between koha table fields and MARC field/subfield
331
    $self->{"marcfromkohafield"} = undef; # the hash with relations between koha table fields and MARC field/subfield
(-)a/Koha/Cache.pm (-4 / +3 lines)
Lines 75-81 sub new { Link Here
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
    $self->{'namespace'} ||= $ENV{MEMCACHED_NAMESPACE} || 'koha';
78
    $self->{'namespace'} ||= $ENV{MEMCACHED_NAMESPACE} || C4::Context->config('memcached_namespace') || 'koha';
79
    $self->{namespace} .= ":$subnamespace:";
79
    $self->{namespace} .= ":$subnamespace:";
80
80
81
    if ( $self->{'default_type'} eq 'memcached'
81
    if ( $self->{'default_type'} eq 'memcached'
Lines 113-120 sub new { Link Here
113
113
114
sub _initialize_memcached {
114
sub _initialize_memcached {
115
    my ($self) = @_;
115
    my ($self) = @_;
116
    my @servers = split /,/, $ENV{MEMCACHED_SERVERS} || '';
116
    my @servers = split /,/, $ENV{MEMCACHED_SERVERS} || C4::Context->config('memcached_servers') || '';
117
    return if !@servers;
117
    return unless @servers;
118
118
119
    $ENV{DEBUG}
119
    $ENV{DEBUG}
120
      && carp "Memcached server settings: "
120
      && carp "Memcached server settings: "
121
- 

Return to bug 16579