
Django Caching
Cache backends, per-view cache, template fragment cache, low-level cache API, cache invalidation
1What is the default cache backend in Django if no configuration is specified?
What is the default cache backend in Django if no configuration is specified?
Risposta
Django uses the 'LocMemCache' backend (local memory cache) by default which stores data in the Python process memory. This backend is simple and fast but doesn't persist between server restarts and doesn't share data across different processes. It's suitable for development but not recommended for multi-process production environments.
2Which decorator should be used to cache the complete response of a view for 15 minutes?
Which decorator should be used to cache the complete response of a view for 15 minutes?
Risposta
The cache_page decorator from django.views.decorators.cache caches the complete HTTP response of a view. The parameter is the time in seconds (15 minutes = 900 seconds). The cache key is automatically generated from the URL and query parameters. This decorator also handles appropriate HTTP headers for caching.
3What is the correct syntax for the template tag to cache a template fragment for 5 minutes?
What is the correct syntax for the template tag to cache a template fragment for 5 minutes?
Risposta
The {% cache %} tag caches a template fragment. The syntax is {% cache timeout cache_name %}...{% endcache %}. The first argument is the time in seconds (300 for 5 minutes), the second is a unique name to identify this fragment. Additional arguments can be added to vary the cache (e.g., user.id).
How to retrieve a value from cache with a default value if the key doesn't exist?
Which cache backend is recommended for a Django application in production with multiple instances?
+17 domande da colloquio
Altri argomenti di colloquio Django
Python Basics
Python OOP
Django Fundamentals
Django Models - Basics
Django Views
Django Templates
Django Forms
Advanced QuerySets
Django Authentication
Django Middleware
Django Admin
Django REST Framework
Django Signals
File Upload
Django Sessions
Django Email
Django Testing
Django Security
Django Deployment
Advanced Django ORM
Django Performance
Django & Celery
Django Channels
Django & GraphQL
Django & Docker
Django in Microservices Ecosystem
Custom Django Commands
Django Internationalization
Django Design Patterns
Django Async & ASGI
Settings & Production Configuration
Observability & Monitoring
Padroneggia Django per il tuo prossimo colloquio
Accedi a tutte le domande, flashcards, test tecnici, esercizi di code review e simulatori di colloquio.
Inizia gratis