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); |
21 |
use vars qw($VERSION $AUTOLOAD $context @context_stack $servers $memcached $ismemcached); |
22 |
|
22 |
|
23 |
BEGIN { |
23 |
BEGIN { |
24 |
if ($ENV{'HTTP_USER_AGENT'}) { |
24 |
if ($ENV{'HTTP_USER_AGENT'}) { |
Lines 78-83
BEGIN {
Link Here
|
78 |
$main::SIG{__DIE__} = \&CGI::Carp::confess; |
78 |
$main::SIG{__DIE__} = \&CGI::Carp::confess; |
79 |
} |
79 |
} |
80 |
} # else there is no browser to send fatals to! |
80 |
} # else there is no browser to send fatals to! |
|
|
81 |
|
82 |
# Check if there are memcached servers set |
83 |
$servers = $ENV{'MEMCACHED_SERVERS'}; |
84 |
if ($servers) { |
85 |
# Load required libraries and create the memcached object |
86 |
require Cache::Memcached; |
87 |
$memcached = Cache::Memcached->new({ |
88 |
servers => [ $servers ], |
89 |
debug => 0, |
90 |
compress_threshold => 10_000, |
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 |
|
81 |
$VERSION = '3.00.00.036'; |
97 |
$VERSION = '3.00.00.036'; |
82 |
} |
98 |
} |
83 |
|
99 |
|
Lines 229-234
Returns undef in case of error.
Link Here
|
229 |
|
245 |
|
230 |
sub read_config_file { # Pass argument naming config file to read |
246 |
sub read_config_file { # Pass argument naming config file to read |
231 |
my $koha = XMLin(shift, keyattr => ['id'], forcearray => ['listen', 'server', 'serverinfo'], suppressempty => ''); |
247 |
my $koha = XMLin(shift, keyattr => ['id'], forcearray => ['listen', 'server', 'serverinfo'], suppressempty => ''); |
|
|
248 |
|
249 |
if ($ismemcached) { |
250 |
$memcached->set('kohaconf',$koha); |
251 |
} |
252 |
|
232 |
return $koha; # Return value: ref-to-hash holding the configuration |
253 |
return $koha; # Return value: ref-to-hash holding the configuration |
233 |
} |
254 |
} |
234 |
|
255 |
|
Lines 274-279
Allocates a new context. Initializes the context from the specified
Link Here
|
274 |
file, which defaults to either the file given by the C<$KOHA_CONF> |
295 |
file, which defaults to either the file given by the C<$KOHA_CONF> |
275 |
environment variable, or F</etc/koha/koha-conf.xml>. |
296 |
environment variable, or F</etc/koha/koha-conf.xml>. |
276 |
|
297 |
|
|
|
298 |
It saves the koha-conf.xml values in the declared memcached server(s) |
299 |
if currently available and uses those values until them expire and |
300 |
re-reads them. |
301 |
|
277 |
C<&new> does not set this context as the new default context; for |
302 |
C<&new> does not set this context as the new default context; for |
278 |
that, use C<&set_context>. |
303 |
that, use C<&set_context>. |
279 |
|
304 |
|
Lines 308-317
sub new {
Link Here
|
308 |
return undef; |
333 |
return undef; |
309 |
} |
334 |
} |
310 |
} |
335 |
} |
311 |
# Load the desired config file. |
|
|
312 |
$self = read_config_file($conf_fname); |
313 |
$self->{"config_file"} = $conf_fname; |
314 |
|
336 |
|
|
|
337 |
if ($ismemcached) { |
338 |
# retreive from memcached |
339 |
$self = $memcached->get('kohaconf'); |
340 |
if (not defined $self) { |
341 |
# not in memcached yet |
342 |
$self = read_config_file($conf_fname); |
343 |
} |
344 |
} else { |
345 |
# non-memcached env, read from file |
346 |
$self = read_config_file($conf_fname); |
347 |
} |
348 |
|
349 |
$self->{"config_file"} = $conf_fname; |
315 |
warn "read_config_file($conf_fname) returned undef" if !defined($self->{"config"}); |
350 |
warn "read_config_file($conf_fname) returned undef" if !defined($self->{"config"}); |
316 |
return undef if !defined($self->{"config"}); |
351 |
return undef if !defined($self->{"config"}); |
317 |
|
352 |
|