Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the data exists in the cache.
Azure
if cache.[1](key):
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' instead of a method that checks existence.
Using 'contains' which is not a valid method here.
✗ Incorrect
The exists method checks if the key exists in the cache.
2fill in blank
mediumComplete the code to retrieve data from the cache.
Azure
data = cache.[1](key) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fetch' or 'retrieve' which are not valid cache methods.
Using 'load' which is not a cache method.
✗ Incorrect
The get method retrieves the value for the given key from the cache.
3fill in blank
hardFix the error in the code to store data in the cache.
Azure
cache.[1](key, data, expiration=3600)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'store' or 'put' which are not valid Azure Cache methods.
Using 'save' which is not a cache method.
✗ Incorrect
The set method stores data in the cache with an optional expiration time.
4fill in blank
hardFill both blanks to implement cache-aside pattern: fetch from cache or load from database.
Azure
if not cache.[1](key): data = database.[2](key) cache.set(key, data)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' in first blank which retrieves data but does not check existence.
Using 'fetch' for database which is not the method here.
✗ Incorrect
First, check if the key exists in cache with exists. If not, load data from database using load.
5fill in blank
hardFill all three blanks to complete cache-aside pattern with expiration time.
Azure
if not cache.[1](key): data = database.[2](key) cache.[3](key, data, expiration=300)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' instead of 'exists' to check existence.
Using 'fetch' instead of 'load' for database.
Using 'save' instead of 'set' to store cache.
✗ Incorrect
Check cache key existence with exists, load data from database with load, then store in cache with set including expiration.