0
0
Djangoframework~10 mins

Low-level cache API in Django - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the cache object from Django's cache framework.

Django
from django.core.cache import [1]
Drag options to blanks, or click blank then click option'
ACacheHandler
Bcaches
Ccache_control
Dcache
Attempts:
3 left
💡 Hint
Common Mistakes
Importing caches instead of cache when only one cache is used.
Trying to import cache_control which is unrelated.
2fill in blank
medium

Complete the code to set a cache key 'greeting' with value 'hello' that expires in 30 seconds.

Django
cache.[1]('greeting', 'hello', timeout=30)
Drag options to blanks, or click blank then click option'
Aget
Bset
Cdelete
Dclear
Attempts:
3 left
💡 Hint
Common Mistakes
Using get which only retrieves data.
Using delete which removes data.
3fill in blank
hard

Fix the error in the code to retrieve the value of cache key 'greeting'.

Django
value = cache.[1]('greeting')
Drag options to blanks, or click blank then click option'
Aadd
Bset
Cget
Dfetch
Attempts:
3 left
💡 Hint
Common Mistakes
Using set which stores data instead of retrieving.
Using fetch which is not a valid cache method.
4fill in blank
hard

Fill both blanks to delete a cache key 'greeting' and then clear all cache keys.

Django
cache.[1]('greeting')
cache.[2]()
Drag options to blanks, or click blank then click option'
Adelete
Bclear
Cset
Dget
Attempts:
3 left
💡 Hint
Common Mistakes
Using set or get instead of delete or clear.
Mixing up the order of methods.
5fill in blank
hard

Fill all three blanks to add a cache key 'counter' with value 1 only if it does not exist, then increment it by 1.

Django
cache.[1]('counter', 1)
counter = cache.[2]('counter')
counter = counter [3] 1
Drag options to blanks, or click blank then click option'
Aadd
Bget
C+
Dset
Attempts:
3 left
💡 Hint
Common Mistakes
Using set instead of add which overwrites existing keys.
Trying to increment the key directly without retrieving.