forked from mysociety/fixmystreet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMemcached.pm
47 lines (38 loc) · 853 Bytes
/
Memcached.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Memcached.pm:
# Tiny FixMyStreet memcached wrapper
package Memcached;
use strict;
use warnings;
use Cache::Memcached;
use FixMyStreet;
my $memcache;
my $namespace = FixMyStreet->config('FMS_DB_NAME') . ":";
my $server = FixMyStreet->config('MEMCACHED_HOST') || '127.0.0.1';
sub instance {
return $memcache //= Cache::Memcached->new({
'servers' => [ "${server}:11211" ],
'namespace' => $namespace,
'debug' => 0,
'compress_threshold' => 10_000,
});
}
sub get {
instance->get(@_);
}
sub set {
instance->set(@_);
}
sub delete {
instance->delete(@_);
}
sub increment {
my $key = shift;
my $timeout = shift;
my $count = instance->incr($key);
if (!defined $count) {
instance->add($key, 0, $timeout);
$count = instance->incr($key);
};
return $count;
}
1;