|
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->{"userenv"} = undef; # User env |
331 |
$self->{"userenv"} = undef; # User env |