0
0
Rest APIprogramming~10 mins

Expiration-based caching in Rest API - Interactive Code Practice

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

Complete the code to set the cache expiration time to 60 seconds.

Rest API
cache.set('user_data', data, expire=[1])
Drag options to blanks, or click blank then click option'
A60
B600
C6
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 which means no expiration.
Using 600 which is 10 minutes, not 1 minute.
2fill in blank
medium

Complete the code to check if the cached data has expired before returning it.

Rest API
if cache.get('user_data') is not [1]:
    return cache.get('user_data')
Drag options to blanks, or click blank then click option'
A0
BFalse
CTrue
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for False instead of None.
Using 0 which is a valid value but not the absence of data.
3fill in blank
hard

Fix the error in the code to correctly update the cache with new data and expiration.

Rest API
cache.[1]('user_data', new_data, expire=120)
Drag options to blanks, or click blank then click option'
Aset
Bupdate
Cput
Dadd
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'update' which may not exist.
Using 'add' which might only add if key doesn't exist.
4fill in blank
hard

Fill both blanks to create a cache dictionary comprehension that stores word lengths only for words longer than 3 characters.

Rest API
cache_data = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<=
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as value instead of its length.
Using '<=' instead of '>' causing wrong filtering.
5fill in blank
hard

Fill all three blanks to create a cache dictionary comprehension that stores uppercase words as keys and their lengths as values, only if length is greater than 4.

Rest API
cache_data = { [1]: [2] for word in words if len(word) [3] 4 }
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
C>
Dword.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using word.lower() instead of word.upper() for keys.
Using '<' instead of '>' in the condition.