title: Russian doll fragment caching with auto expiring keys - performance pros and cons
body: <p>The question is based on 2 articles:<br>
  - <a href="http://37signals.com/svn/posts/3113-how-key-based-cache-expiration-works"> Basecamp Next </a> by DHH from 37signals<br>
  - <a href="http://broadcastingadam.com/2012/07/advanced_caching_part_2-using_strategies/"> Advanced Caching in Rails</a> by Adam Hawkins</p>
  
  <p>I'm a little bit confused about the performance implications of using Russian doll caching, Specifically: </p>
  
  <ol>
  <li><p>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 ...)</p></li>
  <li><p>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? </p></li>
  <li><p>In the 2nd article Adam  caches chunks of the view like this: 
  <code>cache [post, 'main-content']</code> ...
  <code>cache [post, 'comments']</code>
  When a comment is added it changes the time stamp of post, and therefor invalidates both entires. However, <code>main-content</code> 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. )</p></li>
  </ol>
  
  <p>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. </p>
  
  <p>Any feedback would be appreciated!<br>
  Thanks.  </p>