0
0
Ruby on Railsframework~20 mins

Page and action caching in Ruby on Rails - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Rails Caching Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when a cached page is expired in Rails page caching?

Consider a Rails app using page caching. When the cached page is expired, what is the next behavior when a user requests that page?

ARails serves the stale cached page until the cache is manually refreshed.
BRails redirects the user to the homepage automatically.
CRails returns a 404 error because the cached page is missing.
DRails regenerates the page by running the controller action and updates the cache before serving.
Attempts:
2 left
💡 Hint

Think about how caching helps serve fresh content after expiration.

📝 Syntax
intermediate
2:00remaining
Which code snippet correctly enables action caching in a Rails controller?

Identify the correct way to enable action caching for the show action in a Rails controller.

Acaches_page :show
Bcache_action :show
Ccaches_action :show
Dcache_page :show
Attempts:
2 left
💡 Hint

Look for the exact Rails method name for action caching.

🔧 Debug
advanced
2:00remaining
Why does the cached page not update after data changes in Rails page caching?

A Rails app uses page caching, but after updating the database, the cached page still shows old data. What is the most likely cause?

AThe cache was not expired or deleted after the data update.
BThe controller action is missing the <code>caches_action</code> call.
CThe view template has syntax errors preventing cache refresh.
DThe server is running in development mode, which disables caching.
Attempts:
2 left
💡 Hint

Think about what triggers cache refresh in page caching.

🧠 Conceptual
advanced
2:00remaining
What is a key difference between page caching and action caching in Rails?

Choose the statement that best describes a fundamental difference between page caching and action caching.

APage caching stores the entire response as a static file, bypassing Rails, while action caching runs filters before serving cached content.
BAction caching stores static files on disk, while page caching caches only controller variables.
CPage caching requires database queries on every request, action caching does not.
DAction caching is faster because it skips the controller entirely.
Attempts:
2 left
💡 Hint

Consider how each caching type interacts with the Rails stack.

state_output
expert
3:00remaining
What is the output after running this Rails action caching code snippet?

Given the following Rails controller snippet with action caching enabled, what will be the value of @count after two consecutive requests?

Ruby on Rails
class ItemsController < ApplicationController
  caches_action :index

  def index
    @count ||= 0
    @count += 1
    render plain: "Count: #{@count}"
  end
end
A"Count: 1" on first request, "Count: 2" on second request
B"Count: 1" on first request, "Count: 1" on second request
C"Count: 0" on first request, "Count: 1" on second request
D"Count: 2" on first request, "Count: 3" on second request
Attempts:
2 left
💡 Hint

Remember how action caching serves cached content without rerunning the action.