0
0
Djangoframework~20 mins

Cache framework configuration in Django - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cache Configuration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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']
A300
BNone
C0
D60
Attempts:
2 left
💡 Hint
Look at the TIMEOUT value set in the default cache dictionary.
📝 Syntax
intermediate
2:00remaining
Which cache backend setting is syntactically correct?
Identify the correct Django cache backend setting syntax.
A'BACKEND': 'django.core.cache.backends.memcached.MemcacheCache'
B'BACKEND': 'django.core.cache.backends.memcached.Memcached'
C'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache'
D'BACKEND': 'django.core.cache.backends.memcached.CacheMemcached'
Attempts:
2 left
💡 Hint
Check the official Django cache backend class names.
🔧 Debug
advanced
2: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,
    }
}
ATIMEOUT cannot be set in cache configuration
BInvalid backend name causes ImportError
CLOCATION value must be an integer, not string
DMissing comma after 'LocMemCache' string causes SyntaxError
Attempts:
2 left
💡 Hint
Look carefully at the dictionary syntax between keys.
state_output
advanced
2: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')
A'world'
B'hello'
CNone
DRaises KeyError
Attempts:
2 left
💡 Hint
The second set call overwrites the first with no timeout.
🧠 Conceptual
expert
3: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.
A{'BACKEND': 'django.core.cache.backends.memcached.PyMemcacheCache', 'LOCATION': '127.0.0.1:11211'}
B{'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', 'LOCATION': 'unique-snowflake'}
C{'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', 'LOCATION': '/var/tmp/django_cache'}
D{'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}
Attempts:
2 left
💡 Hint
Consider which backend is designed for thread-safe local memory caching.