Bird
0
0

Given this view with per-view caching:

medium📝 component behavior Q4 of 15
Django - Caching
Given this view with per-view caching:
@cache_page(30)
def index(request):
    return HttpResponse(str(time.time()))

What will happen if you refresh the page multiple times within 30 seconds?
AThe response will be empty
BThe response will show a new timestamp on every refresh
CThe server will raise a caching error
DThe response will show the same timestamp for 30 seconds
Step-by-Step Solution
Solution:
  1. Step 1: Understand @cache_page behavior

    @cache_page caches the entire response for the timeout period (30 seconds here).
  2. Step 2: Predict output on refresh

    Within 30 seconds, the cached response is served, so the timestamp stays the same.
  3. Final Answer:

    The response will show the same timestamp for 30 seconds -> Option D
  4. Quick Check:

    Cache serves same response during timeout [OK]
Quick Trick: Cached view returns same output until timeout expires [OK]
Common Mistakes:
MISTAKES
  • Expecting new output on every refresh
  • Thinking caching causes errors
  • Assuming empty response on cache

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes