Hacker News new | ask | show | jobs
by grey-area 4712 days ago
In Rails 4 with russian doll caching, when data or the view changes, the key changes, so rather than expiring keys, you just don't use them again. So you have no real need for expiry or overwrites, as when data changes, the key changes with it (I think they use the object modified date + hash of view template). As far as I can see groupcache would be compatible with that caching scheme, or others like it.

The only bit which could be tricky is if you want to clear the cache, I don't see a way of doing that from a quick look at the API. But to clear the cache you could have a special version key hashed into each key whose sole purpose is to empty the cache, which you bump whenever you want to remove all keys at once for whatever reason (in a perfect world, this shouldn't be necessary of course).

1 comments

The intention with Russian doll caching is that the cache uses LRU, so you don't need to worry about clearing the cache. No poison pill needed. Memcache operates this way.

Given that there's an 'lru' folder with a package that says 'implements a LRU cache' as the first comment, I assume this works that way as well.

Yes in a perfect world you never need to clear everything, but sometimes it's useful for testing or to allow end users to clear the cache in case of caching bugs.