Bird
0
0

Given this Django view with per-view caching:

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

What will happen if you refresh the page multiple times within 60 seconds?
AThe page shows the same timestamp for 60 seconds
BThe page shows a new timestamp on every refresh
CThe page raises an error because time.time() is not cached
DThe page shows timestamps increasing by 60 seconds
Step-by-Step Solution
Solution:
  1. Step 1: Understand what @cache_page(60) does

    It caches the entire response for 60 seconds.
  2. Step 2: Analyze the effect on time.time()

    Since the response is cached, the timestamp won't update until cache expires.
  3. Final Answer:

    The page shows the same timestamp for 60 seconds -> Option A
  4. Quick Check:

    Cache holds output unchanged for timeout [OK]
Quick Trick: Cached view returns same output until timeout expires [OK]
Common Mistakes:
MISTAKES
  • Expecting timestamp to update every refresh
  • Thinking caching only affects database queries
  • Assuming cache raises errors with dynamic content

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes