0
0
HLDsystem_design~10 mins

Cache eviction policies (LRU, LFU, TTL) in HLD - Interactive Code Practice

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

Complete the code to identify the cache eviction policy that removes the least recently used item.

HLD
if cache.is_full():
    cache.evict_policy = "[1]"
Drag options to blanks, or click blank then click option'
ATTL
BLFU
CLRU
DFIFO
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing LRU with LFU or TTL.
2fill in blank
medium

Complete the code to set the cache eviction policy that removes the least frequently used item.

HLD
if cache.needs_eviction():
    cache.policy = "[1]"
Drag options to blanks, or click blank then click option'
ARandom
BLRU
CTTL
DLFU
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing LFU with LRU or TTL.
3fill in blank
hard

Fix the error in the code to correctly implement a time-based cache eviction policy.

HLD
cache.set_eviction_policy("[1]")
cache.expiry_time = 300  # seconds
Drag options to blanks, or click blank then click option'
ATTL
BLRU
CLFU
DFIFO
Attempts:
3 left
💡 Hint
Common Mistakes
Using LRU or LFU where TTL is needed.
4fill in blank
hard

Fill both blanks to complete the dictionary comprehension that filters cache entries by TTL and sorts by usage frequency.

HLD
filtered_cache = {k: v for k, v in cache.items() if v.expiry > [1]
sorted_cache = sorted(filtered_cache.items(), key=lambda item: item[1].[2])
Drag options to blanks, or click blank then click option'
Acurrent_time
Blast_used
Cfrequency
Dexpiry
Attempts:
3 left
💡 Hint
Common Mistakes
Using expiry instead of current_time for filtering.
Sorting by last_used instead of frequency.
5fill in blank
hard

Fill all three blanks to complete the cache eviction function that uses LRU policy with TTL expiration.

HLD
def evict_cache(cache):
    now = [1]
    valid_items = {k: v for k, v in cache.items() if v.expiry > now}
    lru_key = min(valid_items, key=lambda k: valid_items[k].[2])
    del cache[lru_key]
    return cache

current_time = [3]
Drag options to blanks, or click blank then click option'
Atime.time()
Blast_accessed
Cdatetime.now()
Dexpiry
Attempts:
3 left
💡 Hint
Common Mistakes
Using expiry instead of last_accessed for LRU.
Using datetime.now() inconsistently.