0
0
Djangoframework~5 mins

Per-view caching in Django - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is per-view caching in Django?
Per-view caching stores the output of a specific view so that future requests to that view return the cached response quickly without re-running the view code.
Click to reveal answer
beginner
How do you enable per-view caching in Django?
You use the decorator @cache_page(timeout) on a view function or method, where timeout is the cache duration in seconds.
Click to reveal answer
beginner
What does the timeout parameter in @cache_page(timeout) control?
It controls how long the cached response is stored before it expires and the view runs again to refresh the cache.
Click to reveal answer
beginner
Can per-view caching improve website speed? How?
Yes. It saves the result of a view so Django can quickly return the cached page without running database queries or complex logic again.
Click to reveal answer
intermediate
What is a limitation of per-view caching?
It caches the entire response for all users, so it may not work well for views that show user-specific data unless you customize the cache key.
Click to reveal answer
Which decorator is used for per-view caching in Django?
A@cached_view
B@cache_response
C@cache_page
D@view_cache
What does the timeout value in @cache_page(timeout) represent?
ANumber of users cached
BNumber of cached views
CCache size in MB
DCache duration in seconds
What happens when a cached view expires in Django?
AThe view runs again and caches new output
BThe cache is deleted permanently
CThe server restarts
DThe user is redirected
Which type of data is NOT ideal for per-view caching?
AFrequently accessed pages
BUser-specific data
CPublic pages
DStatic content
Where do you import the @cache_page decorator from?
Adjango.views.decorators.cache
Bdjango.cache.decorators
Cdjango.utils.cache
Ddjango.views.cache
Explain how to add per-view caching to a Django view and why it helps performance.
Think about how caching saves time by reusing previous results.
You got /4 concepts.
    Describe a scenario where per-view caching might cause problems and how to handle it.
    Think about when different users need different pages.
    You got /4 concepts.