0
0
Rest APIprogramming~10 mins

Why caching reduces server load in Rest API - Test Your Understanding

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

Complete the code to return cached data if available.

Rest API
if cache.get('data') is not [1]:
    return cache.get('data')
Drag options to blanks, or click blank then click option'
AFalse
BNone
CTrue
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using True or False instead of None to check cache presence.
2fill in blank
medium

Complete the code to store response in cache after fetching.

Rest API
response = fetch_data()
cache.[1]('data', response)
Drag options to blanks, or click blank then click option'
Aset
Bdelete
Cget
Dupdate
Attempts:
3 left
💡 Hint
Common Mistakes
Using get instead of set to store data.
3fill in blank
hard

Fix the error in the code to check cache before fetching data.

Rest API
if cache.[1]('data'):
    return cache.get('data')
else:
    data = fetch_data()
    cache.set('data', data)
    return data
Drag options to blanks, or click blank then click option'
Aget
Bcontains
Cexists
Dhas_key
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like has_key or contains.
4fill in blank
hard

Fill both blanks to create a cache dictionary comprehension filtering keys.

Rest API
filtered_cache = {k: v for k, v in cache.items() if k [1] 'user' and v [2] None}
Drag options to blanks, or click blank then click option'
Astartswith
Bendswith
Cis not
Dis
Attempts:
3 left
💡 Hint
Common Mistakes
Using endswith instead of startswith.
Using 'is' instead of 'is not' for None check.
5fill in blank
hard

Fill all three blanks to create a cache update with conditional filtering.

Rest API
cache_update = [1]: [2] for [3], val in new_data.items() if val > 0
Drag options to blanks, or click blank then click option'
Akey
Bval
Ck
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing variable names or using undefined names.