Lines 81-87
sub new {
Link Here
|
81 |
$self->{'timeout'} ||= 0; |
81 |
$self->{'timeout'} ||= 0; |
82 |
$self->{'namespace'} ||= $ENV{MEMCACHED_NAMESPACE} || 'koha'; |
82 |
$self->{'namespace'} ||= $ENV{MEMCACHED_NAMESPACE} || 'koha'; |
83 |
|
83 |
|
84 |
if ( can_load( modules => { 'Cache::Memcached' => undef } ) ) { |
84 |
if ( can_load( modules => { 'Cache::Memcached::Fast' => undef } ) ) { |
85 |
_initialize_memcached($self); |
85 |
_initialize_memcached($self); |
86 |
if ( $self->{'default_type'} eq 'memcached' |
86 |
if ( $self->{'default_type'} eq 'memcached' |
87 |
&& defined( $self->{'memcached_cache'} ) ) |
87 |
&& defined( $self->{'memcached_cache'} ) ) |
Lines 140-152
sub _initialize_memcached {
Link Here
|
140 |
. " with " |
140 |
. " with " |
141 |
. $self->{'namespace'}; |
141 |
. $self->{'namespace'}; |
142 |
# Cache::Memcached::Fast doesn't allow a default expire time to be set |
142 |
# Cache::Memcached::Fast doesn't allow a default expire time to be set |
143 |
my $memcached = Cache::Memcached->new( |
143 |
# so we force it on setting. |
|
|
144 |
my $memcached = Cache::Memcached::Fast->new( |
144 |
{ |
145 |
{ |
145 |
servers => \@servers, |
146 |
servers => \@servers, |
146 |
compress_threshold => 10_000, |
147 |
compress_threshold => 10_000, |
147 |
namespace => $self->{'namespace'}, |
148 |
namespace => $self->{'namespace'}, |
148 |
expire_time => 600, |
|
|
149 |
debug => 0, |
149 |
debug => 0, |
|
|
150 |
utf8 => 1, |
150 |
} |
151 |
} |
151 |
); |
152 |
); |
152 |
# Ensure we can actually talk to the memcached server |
153 |
# Ensure we can actually talk to the memcached server |
Lines 255-262
sub set_in_cache {
Link Here
|
255 |
|
256 |
|
256 |
return unless ( $self->{$cache} && ref( $self->{$cache} ) =~ m/^Cache::/ ); |
257 |
return unless ( $self->{$cache} && ref( $self->{$cache} ) =~ m/^Cache::/ ); |
257 |
my $expiry = $options->{expiry}; |
258 |
my $expiry = $options->{expiry}; |
|
|
259 |
$expiry //= $self->{timeout}; |
258 |
my $set_sub = $self->{ref($self->{$cache}) . "_set"}; |
260 |
my $set_sub = $self->{ref($self->{$cache}) . "_set"}; |
259 |
if ( defined $expiry ) { |
261 |
# We consider an expiry of 0 to be inifinite |
|
|
262 |
if ( $expiry ) { |
260 |
return $set_sub |
263 |
return $set_sub |
261 |
? $set_sub->( $key, $value, $expiry ) |
264 |
? $set_sub->( $key, $value, $expiry ) |
262 |
: $self->{$cache}->set( $key, $value, $expiry ); |
265 |
: $self->{$cache}->set( $key, $value, $expiry ); |