0
0
Ruby on Railsframework~10 mins

Low-level caching with Rails.cache - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to write data to the cache with a key.

Ruby on Rails
Rails.cache.[1]("user_1", "John")
Drag options to blanks, or click blank then click option'
Awrite
Bdelete
Cread
Dfetch
Attempts:
3 left
💡 Hint
Common Mistakes
Using read instead of write to store data.
Using fetch when you want to just write without reading.
2fill in blank
medium

Complete the code to read cached data by key.

Ruby on Rails
user_name = Rails.cache.[1]("user_1")
Drag options to blanks, or click blank then click option'
Afetch
Bwrite
Cread
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using write instead of read to get data.
Using fetch when only reading is needed.
3fill in blank
hard

Fix the error in the code to fetch cached data or compute and store it.

Ruby on Rails
user_name = Rails.cache.[1]("user_1") { "John" }
Drag options to blanks, or click blank then click option'
Awrite
Bfetch
Cread
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using read which does not accept a block.
Using write which does not read existing data.
4fill in blank
hard

Fill both blanks to write data with expiration time in seconds.

Ruby on Rails
Rails.cache.write("session_123", "active", expires_in: [1].[2])
Drag options to blanks, or click blank then click option'
A5
Bminutes
Cseconds
Dhours
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string like '5 seconds' instead of separate number and unit.
Using wrong units like 'hours' when seconds are intended.
5fill in blank
hard

Fill all three blanks to fetch cached data with a block and set expiration.

Ruby on Rails
user = Rails.cache.fetch("user_42", expires_in: [1].[2]) { [3] }
Drag options to blanks, or click blank then click option'
A10
Bminutes
CUser.find(42)
Dseconds
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the block code outside the block braces.
Using wrong expiration units or values.