Memcache on Rails with Dalli not expiring

This was a little bit of a stumper. In testing, when I tried to cache objects in Memcache with Dalli, by setting expires_in to, say, 5.seconds, the cache didn’t seem to expire.

After debugging into Dalli, I now see why:

# dalli-1.1.4/lib/active_support/cache/dalli_store.rb:131
if expires_in > 0 && !options[:raw]
  # Set the memcache expire a few minutes in the future to support race condition ttls on read
  expires_in += 5.minutes
end

Dalli adds 5 minutes to the expires_in for all cache writes.

Tags: , ,

Leave a Reply