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?
✗ Incorrect
The correct decorator for per-view caching in Django is @cache_page.
What does the timeout value in @cache_page(timeout) represent?
✗ Incorrect
Timeout sets how many seconds the cached response is stored before expiring.
What happens when a cached view expires in Django?
✗ Incorrect
When cache expires, Django runs the view again and stores the fresh output.
Which type of data is NOT ideal for per-view caching?
✗ Incorrect
Per-view caching caches the same response for all users, so user-specific data can cause incorrect content to be shown.
Where do you import the @cache_page decorator from?
✗ Incorrect
The @cache_page decorator is imported from django.views.decorators.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.