in reply to Re: Memcached and arrays?
in thread Memcached and arrays?

my @items_to_stored = qw( a b c ); $memd->set("mem_id_cache", \@items_to_stored); my $stored_items = $memd->get("mem_id_cache"); print "$_\n" for @$stored_items;

Surely, that would only work, if at all, if you retrieve the array ref in the same process as you stored it. Otherwise the reference would just point to some random chunk of (probably unallocated) memory.

And what is the point of storing a ref in a cache then retreiving it, when you have direct access to the data it points to?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"I'd rather go naked than blow up my ass"

Replies are listed 'Best First'.
Re^3: Memcached and arrays?
by ikegami (Patriarch) on Jan 21, 2010 at 06:17 UTC

    No, it serialises and deserialises data structures for you (using Storable::freeze and Storable::thaw by default). $stored_items holds a reference to a copy of the original array.

Re^3: Memcached and arrays?
by expresspotato (Beadle) on Jan 21, 2010 at 06:05 UTC
    This was a simple test if I could actually store results in Memcached then retrieve them at a later time. Success!

      Ignore!

      The point is that if you only store an array reference, and then retreive that reference in the same process, then the reference will still point to the array, and you'll be able to access its contents through it.

      But if you stored the reference in one process, and then retrieved it in another, then that reference will not point to anything in the new process and if you attempt to dereference it, you'll probably crash perl.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.