Challenge - 5 Problems
Cache Configuration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this Django cache configuration?
Given the following Django cache settings, what will be the cache timeout for the default cache?
Django
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'unique-snowflake',
'TIMEOUT': 300,
}
}
cache_timeout = CACHES['default']['TIMEOUT']Attempts:
2 left
💡 Hint
Look at the TIMEOUT value set in the default cache dictionary.
✗ Incorrect
The TIMEOUT key in the cache configuration sets the cache expiration time in seconds. Here it is set to 300 seconds.
📝 Syntax
intermediate2:00remaining
Which cache backend setting is syntactically correct?
Identify the correct Django cache backend setting syntax.
Attempts:
2 left
💡 Hint
Check the official Django cache backend class names.
✗ Incorrect
The correct backend class for Memcached in Django is 'MemcachedCache'. Other options are invalid class names.
🔧 Debug
advanced2:00remaining
Why does this cache configuration raise an error?
Examine the following cache configuration and identify the cause of the error.
Django
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'unique-snowflake',
'TIMEOUT': 300,
}
}Attempts:
2 left
💡 Hint
Look carefully at the dictionary syntax between keys.
✗ Incorrect
The missing comma after the 'BACKEND' value causes a syntax error in the dictionary definition.
❓ state_output
advanced2:00remaining
What is the value of cache key after this code runs?
Given this Django cache usage code, what will be the value of 'my_key' in the cache after execution?
Django
from django.core.cache import cache cache.set('my_key', 'hello', timeout=10) cache.set('my_key', 'world', timeout=None) value = cache.get('my_key')
Attempts:
2 left
💡 Hint
The second set call overwrites the first with no timeout.
✗ Incorrect
The second cache.set call replaces the value with 'world' and sets timeout to None, meaning it never expires.
🧠 Conceptual
expert3:00remaining
Which cache configuration ensures thread-safe in-memory caching in Django?
Select the cache backend configuration that provides thread-safe in-memory caching suitable for development.
Attempts:
2 left
💡 Hint
Consider which backend is designed for thread-safe local memory caching.
✗ Incorrect
LocMemCache is thread-safe and stores cache in local memory, ideal for development and testing.