Ruby on Rails - russian doll caching in ruby on rails- ruby on rails tutorial - rails guides - rails tutorial - ruby rails
Russian Doll Caching
- We may want to nest cached fragments inside other cached fragments. This is called Russian doll caching.
- The advantage of Russian doll caching is that if a single product is updated, all the other inner fragments can be reused when regenerating the outer fragment.
- As explained in the previous section, a cached file will expire if the value of updated_at changes for a record on which the cached file directly depends. However, this will not expire any cache the fragment is nested within.
- For example, take the following view:
- Which in turn renders this view:
- Any attribute of game is changed, the updated_at value will be set to the current time, thereby expiring the cache.
- However, because updated_at will not be changed for the product object, that cache will not be expired and our app will serve stale data. To fix this, we tie the models together with the touch method: