| Cache::Memcached::Fast::Safe(3pm) | User Contributed Perl Documentation | Cache::Memcached::Fast::Safe(3pm) |
Cache::Memcached::Fast::Safe - Cache::Memcached::Fast with sanitizing keys and fork-safe
use Cache::Memcached::Fast::Safe;
my $memd = Cache::Memcached::Fast::Safe->new({
servers => [..]
});
#This module supports all method that Cache::Memcached::Fast has.
Cache::Memcached::Fast::Safe is subclass of 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.
$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)
});
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;
};
Masahiro Nagano <kazeburo {at} gmail.com>
Cache::Memcached::Fast, <http://gihyo.jp/dev/feature/01/memcached_advanced/0002> (Japanese)
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| 2023-02-03 | perl v5.36.0 |