md5 as the key

John Kramlich john.kramlich at gigoit.org
Fri Sep 7 23:12:53 UTC 2007


I use Memcache to cache results of MySQL queries.  I've found that using 
an MD5 hash of the SQL statement works well as the key.  I don't know 
the probability of issues where two different sets of data will produce 
the same MD5.  If you find that out please post to the list.

As far as speed goes, the time to perform an MD5 hash is negligible 
compared to time to hit MySQL vs Memcache.  Of course, my SQL statements 
are relatively short in length.

An MD5 hash also has the added benefit of the short key length which I 
can only assume allows you to cram more data into a smaller allocation 
of RAM.

- John

Venkatesh KS wrote:
> folks,
>
> memcached supports variable length keys. But I am just curious as to 
> why not use md5 instead of lengthy keys. The keylen requirements for 
> my cache (which is very similar to  squid proxy) is very high and I am 
> planning on using md5. I will read up to find out about the false 
> positive probability. But going md5 way will certainly cap the keylen 
> to 16bytes.
>
> regards,
> -venkatesh



More information about the memcached mailing list