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

(-)a/Koha/Cache.pm (-4 / +7 lines)
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 );
(-)a/t/Cache.t (-3 / +15 lines)
Lines 5-11 Link Here
5
use strict;
5
use strict;
6
use warnings;
6
use warnings;
7
7
8
use Test::More tests => 29;
8
use Test::More tests => 32;
9
9
10
my $destructorcount = 0;
10
my $destructorcount = 0;
11
11
Lines 18-24 BEGIN { Link Here
18
SKIP: {
18
SKIP: {
19
    my $cache = Koha::Cache->get_instance();
19
    my $cache = Koha::Cache->get_instance();
20
20
21
    skip "Cache not enabled", 25
21
    skip "Cache not enabled", 28
22
      unless ( $cache->is_cache_active() && defined $cache );
22
      unless ( $cache->is_cache_active() && defined $cache );
23
23
24
    # test fetching an item that isnt in the cache
24
    # test fetching an item that isnt in the cache
Lines 134-139 SKIP: { Link Here
134
134
135
    $hash{'key'} = 'value';
135
    $hash{'key'} = 'value';
136
    is($myhash->{'key'}, 'value', 'retrieved value after clearing cache');
136
    is($myhash->{'key'}, 'value', 'retrieved value after clearing cache');
137
138
    # UTF8 testing
139
    my $utf8_str = "A Møøse once bit my sister";
140
    $cache->set_in_cache('utf8_1', $utf8_str);
141
    is($cache->get_from_cache('utf8_1'), $utf8_str, 'Simple 8-bit UTF8 correctly retrieved');
142
    $utf8_str = "\x{20ac}"; # €
143
    $cache->set_in_cache('utf8_1', $utf8_str);
144
    my $utf8_res = $cache->get_from_cache('utf8_1');
145
    # This'll ensure that we're getting a unicode string back, rather than
146
    # a couple of bytes.
147
    is(length($utf8_res), 1, 'UTF8 string length correct');
148
    # ...and that it's really the character we intend
149
    is(ord($utf8_res), 8364, 'UTF8 string value correct');
137
}
150
}
138
151
139
END {
152
END {
140
- 

Return to bug 12041