As an opportunity to get my latest project so damn fast, I looked into
key-based cache expiration, also known as the Russion Doll approach to
There is something I don’t understand.
"You deal with dependency structures by tying the model objects together
So if you change a todo that belongs to a todolist that belongs to a
project, you update the updated_at timestamp on every part of the chain,
which will automatically then update the cache keys based on these objects
Okay, so the hierarchy is project -> todolist -> todo. Then a single
item, probably keeps track of its creator, right?
In Rails it could be declared like this:
class Project < ActiveRecord::Base
class Todolist < ActiveRecord::Base
belongs_to :project, touch: true
class Todo < ActiveRecord::Base
belongs_to :todolist, touch: true
<% cache project do %>
All my todo lists:<%= render project.todolists %> <% end %>
<% cache todolist do %>
<%= todolist.name %>:<%= render todolist.todos %> <% end %>
<% cache todo do %>
<%= todo.name %>(by <%= todo.creator.name %>)<% end %>
This will not trigger todo.touch!,
which in turn does not trigger todo.todolist.touch!
and does not trigger todo.todolist.project.touch!
todo.creator.update_attributes(name: ‘John D.’)
What do I need to change in order to make this process trivial to
caching schemes and trust that I am never going to serve stale data?