The question is based on 2 articles:
- Basecamp Next by DHH from 37signals
- Advanced Caching in Rails by Adam Hawkins
I'm a little bit confused about the performance implications of using Russian doll caching, Specifically:
When using auto expiring keys it seems like every request will result in an access to the database to fetch the object timestamp - am I missing something? (I understand that in the best case scenario you have to do that only for the top level key in the hierarchy, but still ...)
In the 1st article they cache a todo list, as well as every todo item. Caching the list makes perfect sense as it saves a lot of work (DB query for all the items). But why cache the individual items? You are already going to the database to get the Item timestamp, so what exactly are you saving? Generating a few html lines?
In the 2nd article Adam caches chunks of the view like this:
cache [post, 'main-content']
...cache [post, 'comments']
When a comment is added it changes the time stamp of post, and therefor invalidates both entires. However,main-content
hasn't changed - you don't want to regenerate it!!! How would one go about invalidating only comments. (That's actually a very common user case - a model that has a few logically independent parts: the object itself, the different associations, data in some other store, etc. )
To me it seems like Russian doll caching makes sense only when you have a deep hierarchy of nested object.(in basecamp you have project->todos list -> todo -> items list). However, if you have a shallow hierarchy, it's better to just do the invalidation yourself.
Any feedback would be appreciated!
Thanks.