Subscribed unsubscribe Subscribe Subscribe

Hateburo: kazeburo hatenablog

Operations Engineer / Site Reliability / 運用系小姑 / Perl Monger

Cache::Memcached::Fast::Safe 0.04 was out. It has get_or_set()

I added get_or_set() to Cache::Memcached::Fast::Safe and released as ver. 0.04

https://metacpan.org/release/Cache-Memcached-Fast-Safe

I saw some people make a module that inherits Cache::Memcached::Fast::Safe only for adding get_or_set().

sample code

use Cache::Memcached::Fast::Safe;
 
my $memd = Cache::Memcached::Fast::Safe->new({
  servers => [..]
});
$memcached->get_or_set('key:'.$id,sub {
  MyDB->retrieve($id)
},$expires);

#or 

$memcached->get_or_set('key:'.$id,sub {
  my $val = MyDB->retrieve($id);
  return ($val, $expires)
});