What is Django caching?
Why Interviewers Ask This
Foundational questions like this help interviewers calibrate the rest of the interview. A confident, accurate answer signals that you have solid Django basics — a prerequisite for any developer role.
Answer
Django's caching framework stores expensive computations or database query results for faster subsequent access. Cache backends: Memcached (django.core.cache.backends.memcached.PyMemcacheCache), Redis (django_redis.cache.RedisCache), Database (django.core.cache.backends.db.DatabaseCache), File system, Local memory (development only). Configuration (Redis example): CACHES = {"default": {"BACKEND": "django_redis.cache.RedisCache", "LOCATION": "redis://127.0.0.1:6379/1", "OPTIONS": {"CLIENT_CLASS": "django_redis.client.DefaultClient"}, "TIMEOUT": 300}}. Cache API: from django.core.cache import cache cache.set("key", value, timeout=3600) cache.get("key") cache.get("key", default="fallback") cache.delete("key") cache.set_many({"k1": v1, "k2": v2}) cache.get_many(["k1", "k2"]) cache.incr("view_count") cache.clear(). Per-view caching: @cache_page(60 * 15) # Cache 15 minutes def my_view(request): .... Template fragment caching: {% load cache %}{% cache 900 sidebar request.user.id %}...{% endcache %}. Low-level caching pattern: def get_user_stats(user_id): key = f"user_stats_{user_id}"; result = cache.get(key) if result is None: result = expensive_query(user_id); cache.set(key, result, 3600) return result. Cache versioning and invalidation: use cache.delete() on data changes or use versioned keys.
Pro Tip
If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.