0
0
Djangoframework~5 mins

Template fragment caching in Django - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is template fragment caching in Django?
Template fragment caching stores parts of a template's rendered output to speed up page loading by reusing cached HTML instead of rendering it again.
Click to reveal answer
beginner
How do you mark a part of a Django template for fragment caching?
Use the {% cache %} template tag with a cache timeout and a cache key to wrap the part you want to cache.
Click to reveal answer
beginner
Example of using {% cache %} tag in Django template?
Example: {% cache 600 sidebar %} ... HTML for sidebar ... {% endcache %} caches the sidebar for 600 seconds.
Click to reveal answer
intermediate
Why use template fragment caching instead of full page caching?
Fragment caching lets you cache only slow or complex parts of a page, allowing dynamic parts to update without caching the whole page.
Click to reveal answer
intermediate
What happens if the cache key changes in template fragment caching?
If the cache key changes, Django treats it as a new cache entry and renders the fragment again, storing the new output.
Click to reveal answer
Which Django template tag is used for fragment caching?
A{% loadcache %}
B{% cache %}
C{% fragment %}
D{% storecache %}
What does the number in {% cache 300 key %} represent?
ACache priority level
BCache key length
CNumber of times to cache
DCache timeout in seconds
If a cached fragment is expired, what does Django do?
ASkips rendering the fragment
BShows an error
CRenders the fragment again and caches it
DUses the old cached version anyway
Can template fragment caching improve performance when only part of a page is slow?
AYes, by caching just the slow parts
BNo, it caches the whole page
CNo, it slows down rendering
DYes, but only for static pages
What must you do to use {% cache %} tag in your Django template?
ALoad the cache template tag library with {% load cache %}
BImport cache in views.py
CEnable caching in settings.py only
DNo setup needed
Explain how to implement template fragment caching in a Django template and why it helps performance.
Think about wrapping slow parts of your template with a special tag.
You got /4 concepts.
    Describe what happens when a cached fragment expires and how Django handles it.
    Consider what Django does when the cache is no longer valid.
    You got /4 concepts.