Cached::Memcached::Managed references

Elizabeth Mattijsen liz at dijkmat.nl
Mon Feb 18 12:31:24 GMT 2008


Isn't this because the "id" is only part of the real key that 
Cache::Memcached::Managed uses to cache a value?  Please check the 
"DIFFERENCES FROM THE Cache::Memcached API" section in the 
Cache::Memcached::Managed pod!


Liz
===========================================================
At 12:05 PM +0000 2/18/08, Jason Tang wrote:
>A recent annoyance has brought me out of my lurking on london.pm so I'm
>wondering if someone could shed some light on this rather bizarre
>discovery. I'm hoping its something really obvious I've overlooked but
>we'll see.
>
>I've recently started looking into memcached and wanted to try a few
>simple things to try it out and give it a little test drive. The little
>script below seems to imply that the moment I pass the
>Cache::Memcached::Managed object as a reference 'something' changes and
>it doesnt play ball.
>
>-- >8 --
>#!/usr/bin/env perl
>
>use strict;
>use warnings;
>use Cache::Memcached::Managed;
>use Data::Dumper;
>
>
>sub foo {
>     my($attrs) = @_;
>
>     print "  calling foo\n";
>     my $cache = ($attrs->{cache} || undef);
>     my $id = ($attrs->{id} || undef);
>
>     die '$cache isnt Cache::Memcached::Managed'
>         if (not defined $cache or ref($cache) ne 'Cache::Memcached::Managed');
>
>     print Dumper( $cache->get( $id ) );
>}
>
>sub bar {
>     my($cache, $id, $value) = @_;
>
>     $cache->set(
>         value   => $value,
>         id      => $id
>     );
>}
>
>my $value = {
>     a => 'hello',
>     b => 'good bye',
>     c => scalar localtime,
>};
>
>my $cache = Cache::Memcached::Managed->new(
>     data => '10.3.3.204:11211',
>);
>
>my $id = 'FOO';
>
>
>print "  direct get\n";
>print Dumper( $cache->get( $id ) );
>
>foo({ cache => $cache, id => $id });
>
># set directly
>$cache->set(
>     value   => $value,
>     id      => $id
>);
>
># set in method
>bar($cache,$id,$value);
>
>print "  direct get\n";
>print Dumper( $cache->get( $id ) );
>-- >8 --
>
>The output I get is..
>
>   direct get
>$VAR1 = {
>           'c' => 'Mon Feb 18 11:52:50 2008',
>           'a' => 'hello',
>           'b' => 'good bye'
>         };
>   calling foo
>$VAR1 = undef;
>   direct get
>$VAR1 = {
>           'c' => 'Mon Feb 18 11:59:54 2008',
>           'a' => 'hello',
>           'b' => 'good bye'
>         };
>
>
>It seems the call to foo though is a correct object reference but fails.
>the original object reference is fine and still works.
>
>Any clues?
>
>TIA
>
>Jason
>--
>Jason Tang  - email: jason at dragor.net - msn: jason-msn at dragor.net



More information about the london.pm mailing list