Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define the first level cache type.
HLD
cache = [1]Cache() # First level cache for fastest access
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing disk or database for first level cache.
✗ Incorrect
The first level cache is usually an in-memory cache for fastest data retrieval.
2fill in blank
mediumComplete the code to define the second level cache type.
HLD
cache = [1]Cache() # Second level cache for larger but slower storage
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing in-memory cache again or hardware components.
✗ Incorrect
The second level cache is often disk-based to hold more data but slower than memory.
3fill in blank
hardFix the error in the cache eviction policy assignment.
HLD
cache.eviction_policy = '[1]' # Set eviction policy to remove least recently used items
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using FIFO or MRU which do not fit typical cache eviction.
✗ Incorrect
LRU (Least Recently Used) is a common eviction policy for caches to remove old data.
4fill in blank
hardFill both blanks to complete the multi-level cache lookup logic.
HLD
if [1] in L1_cache: return L1_cache[[2]]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'value' or 'item' which are not keys for lookup.
✗ Incorrect
We check if the key is in the first level cache and return the value by the same key.
5fill in blank
hardFill all three blanks to complete the cache update after a miss.
HLD
if key not in L1_cache: data = [1].get(key) L2_cache.[2](key, data) L1_cache.[3](key, data)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using fetch as a method on cache or wrong data source.
✗ Incorrect
On a cache miss, data is fetched from the database, then stored in L2 and L1 caches using put and set methods respectively.