Given a Rails view with nested cache blocks implementing Russian doll caching, what will be the output behavior when the inner cache key changes but the outer cache key remains the same?
<% cache ['outer', @post.updated_at] do %> Outer content <% cache ['inner', @comment.updated_at] do %> Inner comment content <% end %> <% end %>
Think about how nested caches work independently in Russian doll caching.
In Russian doll caching, nested cache blocks are cached separately. If the inner cache key changes, only the inner block is re-rendered. The outer block remains cached if its key is unchanged.
Which option shows the correct syntax to implement Russian doll caching in a Rails partial that caches a post and its comments separately?
Remember that cache with a block uses <% %> tags, not <%= %>.
The cache helper with a block should use ERB tags <% %> because it does not output content directly. Using <%= %> would output the return value of the block, which is not intended.
A developer notices that when a comment is updated, the inner cache block updates correctly, but the outer cache block never expires even when the post is updated. What is the most likely cause?
Check what keys are used for cache expiration.
If the outer cache key does not change when the post updates, the outer cache block will never expire. Including post.updated_at in the cache key ensures it expires when the post changes.
Given the following code, what is the cache key generated for the inner cache block?
<% cache ['post', post.id, post.updated_at] do %>
<% cache ['comment', comment.id, comment.updated_at] do %>
Comment content
<% end %>
<% end %>
Each cache block generates its own key independently.
In Russian doll caching, each cache block generates its own cache key independently. The inner cache key is based only on the inner block's key, not combined with the outer block's key.
Which of the following best explains the main advantage of using Russian doll caching in Rails views?
Think about how nested caching affects rendering efficiency.
Russian doll caching caches nested view fragments separately. This means when a small part changes, only that part is re-rendered, saving time and resources compared to re-rendering the whole view.