Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to show where cached data is stored.
HLD
cache = [1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing disk or database instead of in-memory storage.
✗ Incorrect
Caching stores data in in-memory to allow faster access than disk or network.
2fill in blank
mediumComplete the code to check if data is in cache before fetching from source.
HLD
if key [1] cache: return cache[key]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'not in' which checks absence instead of presence.
✗ Incorrect
We check if the key is in the cache to use cached data and reduce latency.
3fill in blank
hardFix the error in the code that updates the cache after fetching data.
HLD
data = fetch_from_source(key)
cache[[1]] = data Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'value' or 'data' as the cache key instead of 'key'.
✗ Incorrect
The cache key must be the key used to fetch data, not the value or data itself.
4fill in blank
hardFill both blanks to complete the code that returns cached data or fetches and caches it.
HLD
if [1] in cache: return cache[[2]]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variables for checking and accessing cache.
✗ Incorrect
Both blanks must be the key to check and retrieve the cached data correctly.
5fill in blank
hardFill all three blanks to complete the caching logic with fetch and store.
HLD
if [1] not in cache: [2] = fetch_from_source([3]) cache[key] = data
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing variable names or using undefined variables.
✗ Incorrect
Check if key is missing, fetch data into data, and use key to store it in cache.