0
0
HLDsystem_design~10 mins

Write-through and write-back caching 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 define the caching policy that writes data to both cache and main storage immediately.

HLD
if cache_policy == [1]:
    write_to_cache(data)
    write_to_storage(data)
Drag options to blanks, or click blank then click option'
Awrite-through
Bread-through
Cwrite-back
Dwrite-around
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing write-back which delays writing to storage.
2fill in blank
medium

Complete the code to define the caching policy that writes data only to cache first and delays writing to storage.

HLD
if cache_policy == [1]:
    write_to_cache(data)
    mark_dirty(data)
Drag options to blanks, or click blank then click option'
Awrite-around
Bwrite-through
Cread-through
Dwrite-back
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing write-through which writes immediately to storage.
3fill in blank
hard

Fix the error in the code to correctly mark data as dirty only in write-back caching.

HLD
if cache_policy == 'write-through':
    write_to_cache(data)
    [1](data)
Drag options to blanks, or click blank then click option'
Amark_dirty
Bwrite_to_storage
Cinvalidate_cache
Dflush_cache
Attempts:
3 left
💡 Hint
Common Mistakes
Using mark_dirty in write-through policy.
4fill in blank
hard

Fill both blanks to complete the code that flushes dirty data from cache to storage and clears the dirty flag.

HLD
if data_is_dirty:
    [1](data)
    [2](data)
Drag options to blanks, or click blank then click option'
Awrite_to_storage
Bmark_dirty
Cclear_dirty_flag
Dinvalidate_cache
Attempts:
3 left
💡 Hint
Common Mistakes
Clearing dirty flag before writing data.
5fill in blank
hard

Fill all three blanks to complete the code that updates cache and handles write-back caching correctly.

HLD
if cache_policy == [1]:
    write_to_cache(data)
    [2](data)
else:
    write_to_cache(data)
    [3](data)
Drag options to blanks, or click blank then click option'
Awrite-through
Bmark_dirty
Cwrite_to_storage
Dwrite-back
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing write-back and write-through actions.