> Hello,
>
> I have been playing with Memcached between two servers using Perl and 
> Memcached::Client which is working great. I would like to take it one step 
> further and use AnyEvent to trigger when a new key and value has been written 
> to Memcached. I am struggling to understand how to do it though as the code I 
> have so far is:
>
> use AnyEvent;
> my $cv = AnyEvent->condvar;
> $client->get('iplist', $cv);
> my $iplist = $cv->recv;
>
> while (($ip,$count) = each(%$iplist)) {
>                 print $ip . "\n";
> }
>
> my $loop = AnyEvent->condvar;
> $loop->recv;
>
> If somebody has this working would be very grateful for an example please.

You can't get a trigger/notification when a new key has been added to
memcached. Windmills do not work that way.

You could poll for a value, but that's not really how you're supposed to
use the thing... The pattern is just:

if (my $var = $memc->get('key')) {
   # Use the cached var
} else {
   my $var = slowdatastore_fetch('key')
   $memc->set('key', $var, 60); # cache it for a minute
}

... and then slowly improving that code as you get more familiar with
memc.

Reply via email to