memcache(3) 1.2.0 released...

John McCaskey johnm at klir.com
Thu Jan 13 09:20:02 PST 2005


On Thu, 2005-01-13 at 03:19 -0700, Timo Ewalds wrote:
> Andrei Nigmatulin wrote:
> 
> >В Срд, 12.01.2005, в 22:15, John McCaskey пишет:
> >  
> >
> >>On Wed, 2005-01-12 at 22:03 +0300, Antony Dovgal wrote:
> >>    
> >>
> >>>On Wed, 12 Jan 2005 11:02:01 -0800
> >>>John McCaskey <johnm at klir.com> wrote:
> >>> 
> >>>      
> >>>
> >>>>If the get() command however returns a FALSE for either my stored
> >>>>FALSE value or for a miss, then I will always have to assume its a
> >>>>miss and hit the slow storage everytime I retrieve a FALSE.  Am I
> >>>>missing something here?  I can't see it if so.
> >>>>        
> >>>>
> >>>Yup, you're missing "===" operator.
> >>>empty string == false, but empty string !== false.
> >>>
> >>>http://www.php.net/manual/en/language.operators.comparison.php
> >>>
> >>>      
> >>>
> >>Sure, but an empty string is not the same as a FALSE if I am storing
> >>both and considering them distinct.  I know about ===.  But I want to
> >>get exactly what I store back from memcached, if I store an '' or a
> >>FALSE then I should get exactly a '' or a FALSE in return and when I
> >>test with === it should match up.
> >>    
> >>
> >
> >As i understand, memcached only stores and retrives strings and does not
> >handle anything else, for example boolean. That's because internally,
> >memcached stores raw bytes and a length, but does not store a type of
> >data.
> >The only Right Way i see here is to store TRUE and FALSE as "1" and "0"
> >strings.
> >
> >  
> >
> Though memcached only stores raw data, if you serialize the data in php, 
> it stores the type of data as a string. It won't be as compact as you 
> might be able to get away with, but it will preserve type as well as value.
> 
> I suggest having get() return false when it has a cache miss. If you 
> want to be able to store ANY type of data, then it doesn't matter what 
> you return, it will conflict with something. To get around that, have 
> get_multi() return an array with only the values that exist. For a call 
> of a single key that resulted in a cache miss, it'd return an empty 
> array. The current pure php library does that, though my pecl wrapper 
> does not (as I don't know how to detect the difference between a cache 
> miss and a value of false).
> 

Memcached stores abitrary binary strings.  It's true it knows nothing
about 'type' unless you use the flags as Sean mentioned, but if your
application knows what type goes with a given key this is of no
consequence.  Thus you can do something like mc->set('keyname', FALSE);
without any concern, so long as everytime you access the value in
'keyname' you know what type (or types) you are expecting back.  

I see no reason (except for the fact that the php api returns FALSE for
a miss) not to just store in this manner if you know to expect FALSE as
a possible value when you do your get.

However, in regards to the original discussion, I will mirror the
current php api and return FALSE for a miss in the single get command,
but also allow a single get to be passed to the multi get command as
Array('key'), and then I will return an empty array (Array()) for a
miss, or Array('key'=>value) for a hit.  This allows you to get a FALSE
from the cache and know its not a miss if you use the multi get format.

I think everyone can be happy with that. Right?

> Timo
-- 
John A. McCaskey
Software Development Engineer
Klir Technologies, Inc.
johnm at klir.com
206.902.2027


More information about the memcached mailing list