Performance: Cache backends (memory, Redis, Memcached)
This affects page load speed by reducing database queries and server processing time through fast data retrieval.
Jump into concepts and practice - no test required
from django.core.cache import cache # Using Redis cache backend shared across servers cache.set('key', 'value', timeout=300) value = cache.get('key')
from django.core.cache import cache # Using default local-memory cache in production cache.set('key', 'value', timeout=300) value = cache.get('key')
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Local-memory cache (per process) | N/A | N/A | Higher server delay causes slower paint | [X] Bad |
| Memcached backend | N/A | N/A | Faster than DB but no persistence causes cold start delays | [!] OK |
| Redis backend | N/A | N/A | Fast, persistent, shared cache reduces server delay | [OK] Good |
settings.py?"BACKEND": "django.core.cache.backends.memcached.PyMemcacheCache", "LOCATION": "127.0.0.1:11211"
cache.set('key', {'a': 1}) and then retrieve it with cache.get('key')?