0
0
HLDsystem_design~10 mins

Why caching reduces latency in HLD - Test Your Understanding

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

Complete the code to show where cached data is stored.

HLD
cache = [1]()
Drag options to blanks, or click blank then click option'
Adatabase
Bnetwork
Cdisk
Din-memory
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing disk or database instead of in-memory storage.
2fill in blank
medium

Complete 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'
Aequals
Bin
Cnot in
Dcontains
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'not in' which checks absence instead of presence.
3fill in blank
hard

Fix 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'
Akey
Bvalue
Cdata
Dsource
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'value' or 'data' as the cache key instead of 'key'.
4fill in blank
hard

Fill 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'
Akey
Bdata
Cvalue
Dsource
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variables for checking and accessing cache.
5fill in blank
hard

Fill 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'
Akey
Bdata
Dsource
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing variable names or using undefined variables.