In my project ProductWidgets I'm using caching heavily and I happen to be in love with Redis and use it for everything I can. I also really like the concept of key-based cache expiration that 37signals recently wrote about.
Now, in a couple of situations I had to add a lot of variables to the cache key to make sure it caches the right thing. Have a look at this example:
def search(category, query, locale, page, per_page) cache_key = [ 'searches', category, query, locale, page, per_page ].join(':') Rails.cache.fetch cache_key do # Heavy lifting end end
It occurred to me that in situations like this, where I basically want to cache the whole method based on the arguments, there must be some automated way of doing this where you don't have to add each argument to the cache key. Imagine some other developer comes along and adds an argument to the method and forgets to add it to the cache key! I do not want to be involved in that bug hunt...