0
0
Ruby on Railsframework~20 mins

Russian doll caching in Ruby on Rails - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Russian Doll Caching Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
Understanding nested cache behavior in Rails views

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?

Ruby on Rails
<% cache ['outer', @post.updated_at] do %>
  Outer content
  <% cache ['inner', @comment.updated_at] do %>
    Inner comment content
  <% end %>
<% end %>
AOnly the inner cache block is re-rendered; the outer cache block is reused from cache.
BBoth inner and outer cache blocks are re-rendered because the inner key changed.
COnly the outer cache block is re-rendered; the inner cache block is ignored.
DNeither cache block is re-rendered; both are reused from cache regardless of key changes.
Attempts:
2 left
💡 Hint

Think about how nested caches work independently in Russian doll caching.

📝 Syntax
intermediate
2:00remaining
Correct syntax for Russian doll caching in Rails partials

Which option shows the correct syntax to implement Russian doll caching in a Rails partial that caches a post and its comments separately?

A
&lt;% cache @post do %&gt;
  &lt;%= render @post %&gt;
  &lt;% cache @post.comments %&gt;
    &lt;%= render @post.comments %&gt;
  &lt;% end %&gt;
&lt;% end %&gt;
B
&lt;%= cache @post do %&gt;
  &lt;%= render @post %&gt;
  &lt;%= cache @post.comments do %&gt;
    &lt;%= render @post.comments %&gt;
  &lt;% end %&gt;
&lt;% end %&gt;
C
&lt;% cache @post do %&gt;
  &lt;%= render @post %&gt;
  &lt;% cache @post.comments do %&gt;
    &lt;%= render @post.comments %&gt;
  &lt;% end %&gt;
&lt;% end %&gt;
D
&lt;%= cache @post do %&gt;
  &lt;%= render @post %&gt;
  &lt;% cache @post.comments %&gt;
    &lt;%= render @post.comments %&gt;
  &lt;% end %&gt;
&lt;% end %&gt;
Attempts:
2 left
💡 Hint

Remember that cache with a block uses <% %> tags, not <%= %>.

🔧 Debug
advanced
2:00remaining
Identifying why nested Russian doll caching is not working

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?

AThe outer cache key does not include the post's <code>updated_at</code> timestamp, so it never expires.
BThe inner cache block is missing a cache key, so it always re-renders.
CThe developer used <code>cache_if</code> instead of <code>cache</code> for the outer block.
DThe Rails cache store is disabled, so no caching happens at all.
Attempts:
2 left
💡 Hint

Check what keys are used for cache expiration.

state_output
advanced
2:00remaining
Cache key generation with nested Russian doll caching

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 %>
AA string like "views/post/123-20240101" ignoring the inner cache key.
BA string like "views/post/123-20240101/comment/456-20240102" combining both keys.
CA string like "views/post/123-20240101/comment/123-20240101" mixing post and comment IDs.
DA string like "views/comment/456-20240102" based only on the inner cache key.
Attempts:
2 left
💡 Hint

Each cache block generates its own key independently.

🧠 Conceptual
expert
3:00remaining
Why use Russian doll caching in Rails applications?

Which of the following best explains the main advantage of using Russian doll caching in Rails views?

AIt caches the entire page as a single fragment, making cache management simpler but less flexible.
BIt allows caching of nested view fragments independently, so only changed parts are re-rendered, improving performance and reducing unnecessary rendering.
CIt automatically invalidates all caches when any nested model changes, ensuring data consistency at the cost of performance.
DIt replaces the need for database query caching by storing all query results in the view cache.
Attempts:
2 left
💡 Hint

Think about how nested caching affects rendering efficiency.