memcached Digest, Vol 30, Issue 5

Jason Pirkey jason at pirkplace.com
Sat Jan 6 15:57:44 UTC 2007


Renato:

I don't just use a hashing of the URL, like Brad suggested.  Just because
sometimes it is nice to see the contents of the key without having to figure
it out.  For example, in profilers, etc.  So what we do is normally have 250
- the hash key size (32 normally -- because we use md5).  So lets say 32.
Take the substring from 0 to 209 of the key, add an underscore as a
separator, and then hash the entire key for the last 40 of the chars to make
it 250.  See code example below as a PHP example:

if (strlen($url) > 217) {
  $hashed_key = substr($url, 0, 217) . '_' . md5($url);
}

This gives you a nice key for looking for debugging and profiling, while
still providing the functionality of keeping them unique.  We do the same
thing for stored procedure calls.  For example, for caching stored procedure
calls, we use the key as the stored procedure name with an an underscore and
the md5 of the parameters.  So that there is uniqueness between the
different parameters that may be passed with it -- id normally.

Hope this helps.

Regards,

Jason Pirkey
jason at pirkplace.com

From: "Renato Silveira" <renatosilveira at gmail.com>
To: memcached at lists.danga.com
Date: Fri, 5 Jan 2007 17:08:05 -0200
Subject: Key Size
Hi,

I´m using memcached as a URL keyword cache. The url is the key and the
cached object is a string with relevant keywords of the site. Well, it´s
working fine for my purpose. The only problem is the limit of key size to
250 bytes(because there can be url bigger than 250 bytes). Well, I tried to
increase the value of the constant KEY_MAX_LENGTH to 2048 bytes. I recompile
memcached and it´s not working. Should I have to make any modification on
the client API? Does anyone can helpme with this issue?

tks!

Renato
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.danga.com/pipermail/memcached/attachments/20070106/2b340117/attachment.htm


More information about the memcached mailing list