19:18 Friday, January 01 2009

0 is worth nothing

Earlier today, I completed the first large project that used memcached. It was a bit of a mess yesterday, when I was (foolishly & erroneously) trying to put non-serialized objects into the cache, and got crap back out. Today, I reworked the code, put sane data into the cache, and mostly got back what I put in. I say mostly, because any time I tried to associate the number 0 with a key in the cache, it never got stored. It took me the better part of an hour to figure this out. Apparently the reason behind this is that there's no way for the memcache client to tell whether the data its getting back is a zero (good) return code, or a real zero value. It might be intentional behavior, but I consider it a bug. Anyway, I worked around it by adding '00' to the cache any time the value was 0, and then any time I got 00 back, converted it back to 0 again.
So memcached is amazing. I had a bunch of php driven reports which had been taking as long as 12 seconds to load. Once the data was all cached, they were taking between 1 & 2 seconds in the worst case, and most took less than 1 second. Overall, I was seeing a greater than 90% reduction in page load times. Awesomeness.