You want to cache a view but exclude caching when a query parameter 'nocache' is present. How can you implement this?
hard📝 Application Q8 of 15
Django - Caching
You want to cache a view but exclude caching when a query parameter 'nocache' is present. How can you implement this?
ASet timeout=0 in @cache_page when 'nocache' is present
BWrite a custom decorator that skips caching if 'nocache' in request.GET
CUse @cache_page with a negative timeout
DAdd @never_cache decorator to the view
Step-by-Step Solution
Solution:
Step 1: Understand conditional caching needs
Standard @cache_page does not support skipping cache based on request data.
Step 2: Choose correct approach
Writing a custom decorator to check request.GET and skip caching is the correct method. timeout=0 disables caching always, negative timeout invalid, @never_cache disables caching always.
Final Answer:
Write a custom decorator that skips caching if 'nocache' in request.GET -> Option B