Caching
django-sysconfig caches every configuration value using Django's standard cache framework. This keeps config reads fast without any configuration on your part — but there are a few things worth knowing, especially in production.
How caching works
Every config.get(path) call goes through the cache:
- Cache hit — the value is deserialized from the cache and returned. No database query.
- Cache miss — the value is fetched from the database, written to the cache, then returned.
Every config.set(path, value) call:
- Writes the new value to the database.
- Updates the cache entry for that path with the new value. No Invalidation, the next get will be fetched from cache.
Cache entries have no expiry time. They are only updated on write. This means config reads are essentially free in steady state — one cache lookup per path per process, then pure in-memory cache hits for all subsequent reads in the same cache entry lifecycle.
Cache backend requirements
django-sysconfig uses whatever cache backend you've configured in CACHES. The default Django cache backend is LocMemCache:
# Django's default — in-memory, per-process
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
}
}LocMemCache works fine in development, but has a critical limitation in production: it's per-process. If you run multiple web workers (e.g., several Gunicorn or uWSGI processes), each process has its own independent cache. A value written by one process invalidates the cache only in that process's memory. Other processes will continue serving stale values until they take a cache miss themselves.
For production, use a shared cache backend:
# Redis (recommended)
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.redis.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/1",
}
}
# Memcached
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.memcached.PyMemcacheCache",
"LOCATION": "127.0.0.1:11211",
}
}With a shared cache, all processes invalidate and read from the same cache layer, so writes propagate immediately across all workers.