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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
# NAME
Cache::Memcached::Fast::Safe - Cache::Memcached::Fast with sanitizing keys and fork-safe
# SYNOPSIS
use Cache::Memcached::Fast::Safe;
my $memd = Cache::Memcached::Fast::Safe->new({
servers => [..]
});
#This module supports all method that Cache::Memcached::Fast has.
# DESCRIPTION
Cache::Memcached::Fast::Safe is subclass of [Cache::Memcached::Fast](https://metacpan.org/pod/Cache::Memcached::Fast).
Cache::Memcached::Fast::Safe sanitizes all requested keys for against
memcached injection problem. and call disconnect\_all automatically after fork
for fork-safe.
# ADDITIONAL METHOD
- get\_or\_set($key:Str, $callback:CodeRef \[,$expires:Num\])
Get a cache value for $key if it's already cached. If can not retrieve cache values, execute $callback and cache with $expires seconds.
$memcached->get_or_set('key:941',sub {
DB->retrieve(941)
},10);
callback can also return expires sec.
$memcached->get_or_set('key:941',sub {
my $val = DB->retrieve(941);
return ($val, 10)
});
# CUSTOMIZE Sanitizer
This module allow to change sanitizing behavior through $Cache::Memcached::Fast::Safe::SANITIZE\_METHOD.
Default sanitizer is
use bytes;
my %escapes = map { chr($_) => sprintf('%%%02X', $_) } (0x00..0x20, 0x7f..0xff);
local $Cache::Memcached::Fast::Safe::SANITIZE_METHOD = sub {
my $key = shift;
$key =~ s/([\x00-\x20\x7f-\xff])/$escapes{$1}/ge;
if ( length $key > 200 ) {
$key = sha1_hex($key);
}
$key;
};
# AUTHOR
Masahiro Nagano <kazeburo {at} gmail.com>
# SEE ALSO
[Cache::Memcached::Fast](https://metacpan.org/pod/Cache::Memcached::Fast), [http://gihyo.jp/dev/feature/01/memcached\_advanced/0002](http://gihyo.jp/dev/feature/01/memcached_advanced/0002) (Japanese)
# LICENSE
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
|