I’m reading this article:
http://37signals.com/svn/posts/3113-how-key-based-cache-expiration-works
I’m not using rails so I don’t really understand their example.
It says in #3:
When the key changes, you simply write the new content to this new
key. So if you update the todo, the key changes from
todos/5-20110218104500 to todos/5-20110218105545, and thus the new
content is written based on the updated object.
How does the view know to read from the new todos/5-20110218105545 instead of the old one?
I was confused about that too at first — how does this save a trip to the database if you have to read from the database anyway to see if the cache is valid? However, see Jesse’s comments (1, 2) from Feb 12th:
and then
And Paul Leader’s comment 2 below that:
So given the models that DHH lists in step 5 of the article and the views he lists in step 6, and given that you’ve properly setup your relationships to
touchthe parent objects on update, and given that your partials access your child data asparent.children, or evenchild.childrenin nested partials, then this caching system should have a net gain because as long as the parent’s cache-key is still valid then theparent.childrenlookup will never happen and will also be pulled from cache, etc.However, this method may be pointless if your partials reference lots of instance variables from the controller since those queries will already have been performed by the time Rails sees the calls to
cachein the view templates. In that case you would probably be better off using other caching patterns.Or at least this is my understanding of how it works. HTH