Complete the code to set a cache key with a timeout in Django.
cache.set('user_123', user_data, timeout=[1])
The timeout value should be an integer representing seconds. Here, 300 means the cache expires after 5 minutes.
Complete the code to delete a cache key in Django.
cache.[1]('user_123')
The delete method removes a specific key from the cache.
Fix the error in the code to invalidate cache after updating a model instance.
def save(self, *args, **kwargs): super().save(*args, **kwargs) cache.[1](f'user_{self.id}')
After saving the model, we delete the cache key to invalidate stale data.
Fill both blanks to create a cache key and set it with a timeout.
cache_key = f'user_[1]' cache.[2](cache_key, user_data, timeout=600)
The cache key uses the user's id. The set method stores data with a timeout.
Fill all three blanks to check cache, set if missing, and return data.
cache_key = f'user_[1]' data = cache.[2](cache_key) if data is None: data = get_user_data([3]) cache.set(cache_key, data, timeout=300) return data
The cache key uses id. We try to get cached data. If missing, we fetch data using user_id and cache it.
