Q:

Good way to invalidate cache entries when view code changes?

I'm using Rails 3.2 and looking for a reliable to invalidate cache entries when a piece of view code is changed. In this article I see that 37signals prefixes the cache key with a version string that is changed each time the view code changes.
For instance if I change All my... to My...
<%= cache ["v1", project] do %>
  <p>All my todo lists:</p>
  [...]
<% end %>

I would make sure cache entries are invalidated by changing v1 to v2
<%= cache ["v2", project] do %>
  <p>My todo lists:</p>
  [...]
<% end %>

Is there a more reliable way to achieve this? I'm concerned we'll forget to update those vX string prefixes when changing a partial or helper code called from the inside the cached block.

A:

You can use cache_digest. It does exactly what you need: invalidates cache fragments automatically when the view is changed. This way you don't need to track each view version manually.

