Complete the code to set the cache expiration time to 60 seconds.
cache.set('user_data', data, timeout=[1])
The timeout parameter defines how long the cache stores data. Setting it to 60 means the cache expires after 60 seconds.
Complete the code to invalidate the cache for the key 'user_data'.
cache.[1]('user_data')
To remove cached data, you use the delete method with the cache key.
Fix the error in the code to invalidate cache after updating user info.
def update_user(user_id, new_info): save_to_db(user_id, new_info) cache.[1](f'user_{user_id}')
After updating the database, you must delete the cache entry to avoid stale data.
Fill both blanks to create a cache key with user ID and set cache with 120 seconds timeout.
cache_key = f'user_[1]' cache.set(cache_key, user_data, timeout=[2])
The cache key uses the variable user_id to identify the user. The timeout is set to 120 seconds for cache expiration.
Fill all three blanks to implement cache invalidation after updating user profile and then set new cache.
def update_profile(user_id, profile): db.update(user_id, profile) cache.[1](f'user_[2]') cache.set(f'user_[3]', profile, timeout=300)
After updating the database, delete the old cache using the user_id key, then set new cache with the updated profile and a 300 seconds timeout.