Lines 51-57
use Koha::Config;
Link Here
|
51 |
use base qw(Class::Accessor); |
51 |
use base qw(Class::Accessor); |
52 |
|
52 |
|
53 |
__PACKAGE__->mk_ro_accessors( |
53 |
__PACKAGE__->mk_ro_accessors( |
54 |
qw( cache memcached_cache fastmmap_cache memory_cache )); |
54 |
qw( cache memcached_cache )); |
55 |
|
55 |
|
56 |
our %L1_cache; |
56 |
our %L1_cache; |
57 |
our $L1_encoder = Sereal::Encoder->new; |
57 |
our $L1_encoder = Sereal::Encoder->new; |
Lines 94-108
sub new {
Link Here
|
94 |
$self->{'cache'} = $self->{'memcached_cache'}; |
94 |
$self->{'cache'} = $self->{'memcached_cache'}; |
95 |
} |
95 |
} |
96 |
|
96 |
|
97 |
if ( $self->{'default_type'} eq 'fastmmap' |
|
|
98 |
&& defined( $ENV{GATEWAY_INTERFACE} ) |
99 |
&& can_load( modules => { 'Cache::FastMmap' => undef } ) |
100 |
&& _initialize_fastmmap($self) |
101 |
&& defined( $self->{'fastmmap_cache'} ) ) |
102 |
{ |
103 |
$self->{'cache'} = $self->{'fastmmap_cache'}; |
104 |
} |
105 |
|
106 |
$ENV{DEBUG} && carp "Selected caching system: " . ($self->{'cache'} // 'none'); |
97 |
$ENV{DEBUG} && carp "Selected caching system: " . ($self->{'cache'} // 'none'); |
107 |
|
98 |
|
108 |
return |
99 |
return |
Lines 141-173
sub _initialize_memcached {
Link Here
|
141 |
return $self; |
132 |
return $self; |
142 |
} |
133 |
} |
143 |
|
134 |
|
144 |
sub _initialize_fastmmap { |
|
|
145 |
my ($self) = @_; |
146 |
my ($cache, $share_file); |
147 |
|
148 |
# Temporary workaround to catch fatal errors when: C4::Context module |
149 |
# is not loaded beforehand, or Cache::FastMmap init fails for whatever |
150 |
# other reason (e.g. due to permission issues - see Bug 13431) |
151 |
eval { |
152 |
$share_file = join( '-', |
153 |
"/tmp/sharefile-koha", $self->{'namespace'}, |
154 |
C4::Context->config('hostname'), C4::Context->config('database') ); |
155 |
|
156 |
$cache = Cache::FastMmap->new( |
157 |
'share_file' => $share_file, |
158 |
'expire_time' => $self->{'timeout'}, |
159 |
'unlink_on_exit' => 0, |
160 |
); |
161 |
}; |
162 |
if ( $@ ) { |
163 |
warn "FastMmap cache initialization failed: $@"; |
164 |
return; |
165 |
} |
166 |
return unless defined $cache; |
167 |
$self->{'fastmmap_cache'} = $cache; |
168 |
return $self; |
169 |
} |
170 |
|
171 |
=head2 is_cache_active |
135 |
=head2 is_cache_active |
172 |
|
136 |
|
173 |
Routine that checks whether or not a default caching method is active on this |
137 |
Routine that checks whether or not a default caching method is active on this |