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); |
|
|
22 |
|
23 |
use Koha::Cache; |
22 |
|
24 |
|
23 |
BEGIN { |
25 |
BEGIN { |
24 |
if ($ENV{'HTTP_USER_AGENT'}) { |
26 |
if ($ENV{'HTTP_USER_AGENT'}) { |
Lines 79-100
BEGIN {
Link Here
|
79 |
} |
81 |
} |
80 |
} # else there is no browser to send fatals to! |
82 |
} # else there is no browser to send fatals to! |
81 |
|
83 |
|
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 |
expire_time => 600, |
92 |
namespace => $ENV{'MEMCACHED_NAMESPACE'} || 'koha' |
93 |
}); |
94 |
# Verify memcached available (set a variable and test the output) |
95 |
$ismemcached = $memcached->set('ismemcached','1'); |
96 |
} |
97 |
|
98 |
$VERSION = '3.00.00.036'; |
84 |
$VERSION = '3.00.00.036'; |
99 |
} |
85 |
} |
100 |
|
86 |
|
Lines 248-285
Returns undef in case of error.
Link Here
|
248 |
sub read_config_file { # Pass argument naming config file to read |
234 |
sub read_config_file { # Pass argument naming config file to read |
249 |
my $koha = XMLin(shift, keyattr => ['id'], forcearray => ['listen', 'server', 'serverinfo'], suppressempty => ''); |
235 |
my $koha = XMLin(shift, keyattr => ['id'], forcearray => ['listen', 'server', 'serverinfo'], suppressempty => ''); |
250 |
|
236 |
|
251 |
if ($ismemcached) { |
237 |
if (Koha::Cache->is_cache_active()) { |
252 |
$memcached->set('kohaconf',$koha); |
238 |
my $cache = Koha::Cache->new(); |
|
|
239 |
$cache->set_in_cache('kohaconf', $koha) if defined $cache; |
253 |
} |
240 |
} |
254 |
|
241 |
|
255 |
return $koha; # Return value: ref-to-hash holding the configuration |
242 |
return $koha; # Return value: ref-to-hash holding the configuration |
256 |
} |
243 |
} |
257 |
|
244 |
|
258 |
=head2 ismemcached |
|
|
259 |
|
260 |
Returns the value of the $ismemcached variable (0/1) |
261 |
|
262 |
=cut |
263 |
|
264 |
sub ismemcached { |
265 |
return $ismemcached; |
266 |
} |
267 |
|
268 |
=head2 memcached |
269 |
|
270 |
If $ismemcached is true, returns the $memcache variable. |
271 |
Returns undef otherwise |
272 |
|
273 |
=cut |
274 |
|
275 |
sub memcached { |
276 |
if ($ismemcached) { |
277 |
return $memcached; |
278 |
} else { |
279 |
return undef; |
280 |
} |
281 |
} |
282 |
|
283 |
# db_scheme2dbi |
245 |
# db_scheme2dbi |
284 |
# Translates the full text name of a database into de appropiate dbi name |
246 |
# Translates the full text name of a database into de appropiate dbi name |
285 |
# |
247 |
# |
Lines 323-331
Allocates a new context. Initializes the context from the specified
Link Here
|
323 |
file, which defaults to either the file given by the C<$KOHA_CONF> |
285 |
file, which defaults to either the file given by the C<$KOHA_CONF> |
324 |
environment variable, or F</etc/koha/koha-conf.xml>. |
286 |
environment variable, or F</etc/koha/koha-conf.xml>. |
325 |
|
287 |
|
326 |
It saves the koha-conf.xml values in the declared memcached server(s) |
288 |
It saves the koha-conf.xml values in the cache (if configured) and uses |
327 |
if currently available and uses those values until them expire and |
289 |
those values until them expire and re-reads them. |
328 |
re-reads them. |
|
|
329 |
|
290 |
|
330 |
C<&new> does not set this context as the new default context; for |
291 |
C<&new> does not set this context as the new default context; for |
331 |
that, use C<&set_context>. |
292 |
that, use C<&set_context>. |
Lines 362-376
sub new {
Link Here
|
362 |
} |
323 |
} |
363 |
} |
324 |
} |
364 |
|
325 |
|
365 |
if ($ismemcached) { |
326 |
if (Koha::Cache->is_cache_active()) { |
366 |
# retreive from memcached |
327 |
# retrieve from cache |
367 |
$self = $memcached->get('kohaconf'); |
328 |
my $cache = Koha::Cache->new(); |
368 |
if (not defined $self) { |
329 |
$self = $cache->get_from_cache('kohaconf') if defined $cache; |
369 |
# not in memcached yet |
330 |
$self = { }; |
370 |
$self = read_config_file($conf_fname); |
331 |
} |
371 |
} |
332 |
if (!keys %$self) { |
372 |
} else { |
333 |
# not cached yet |
373 |
# non-memcached env, read from file |
|
|
374 |
$self = read_config_file($conf_fname); |
334 |
$self = read_config_file($conf_fname); |
375 |
} |
335 |
} |
376 |
|
336 |
|