View | Details | Raw Unified | Return to bug 16067
Collapse All | Expand All

(-)a/Koha/Cache.pm (-37 / +1 lines)
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
(-)a/cpanfile (-1 lines)
Lines 135-141 recommends 'Archive::Extract', '0.60'; Link Here
135
recommends 'Archive::Zip', '1.30';
135
recommends 'Archive::Zip', '1.30';
136
recommends 'Array::Utils', '0.5';
136
recommends 'Array::Utils', '0.5';
137
recommends 'CGI::Session::Driver::memcached', '0.04';
137
recommends 'CGI::Session::Driver::memcached', '0.04';
138
recommends 'Cache::FastMmap', '1.34';
139
recommends 'DBD::SQLite2', '0.33';
138
recommends 'DBD::SQLite2', '0.33';
140
recommends 'Devel::Cover', '0.89';
139
recommends 'Devel::Cover', '0.89';
141
recommends 'File::Copy', '2.08';
140
recommends 'File::Copy', '2.08';
(-)a/debian/control (-2 lines)
Lines 20-26 Build-Depends: libalgorithm-checkdigits-perl, Link Here
20
 libbusiness-isbn-perl,
20
 libbusiness-isbn-perl,
21
 libbusiness-issn-perl,
21
 libbusiness-issn-perl,
22
 libbytes-random-secure-perl,
22
 libbytes-random-secure-perl,
23
 libcache-fastmmap-perl,
24
 libcache-memcached-fast-safe-perl,
23
 libcache-memcached-fast-safe-perl,
25
 libcache-memcached-perl,
24
 libcache-memcached-perl,
26
 libcgi-compile-perl,
25
 libcgi-compile-perl,
Lines 259-265 Depends: libalgorithm-checkdigits-perl, Link Here
259
 libbusiness-isbn-perl,
258
 libbusiness-isbn-perl,
260
 libbusiness-issn-perl,
259
 libbusiness-issn-perl,
261
 libbytes-random-secure-perl,
260
 libbytes-random-secure-perl,
262
 libcache-fastmmap-perl,
263
 libcache-memcached-fast-safe-perl,
261
 libcache-memcached-fast-safe-perl,
264
 libcache-memcached-perl,
262
 libcache-memcached-perl,
265
 libcgi-compile-perl,
263
 libcgi-compile-perl,
(-)a/t/db_dependent/Cache.t (-5 lines)
Lines 284-292 END { Link Here
284
        skip "Cache not enabled", 1
284
        skip "Cache not enabled", 1
285
          unless ( $cache->is_cache_active() );
285
          unless ( $cache->is_cache_active() );
286
        is( $destructorcount, 1, 'Destructor run exactly once' );
286
        is( $destructorcount, 1, 'Destructor run exactly once' );
287
        # cleanup temporary file
288
        my $tmp_file = $cache->{ fastmmap_cache }->{ share_file };
289
        unlink $tmp_file if defined $tmp_file;
290
291
    }
287
    }
292
}
288
}
293
- 

Return to bug 16067