Skip to content

Commit 7e3562e

Browse files
committed
Update caching configuration to use Redis if available, fallback to local memory cache otherwise
1 parent 968e7c6 commit 7e3562e

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

config/settings/production.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,28 @@
2323

2424
# CACHES
2525
# ------------------------------------------------------------------------------
26-
CACHES = {
27-
"default": {
28-
"BACKEND": "django_redis.cache.RedisCache",
29-
"LOCATION": env("REDIS_URL"),
30-
"OPTIONS": {
31-
"CLIENT_CLASS": "django_redis.client.DefaultClient",
32-
# Mimicing memcache behavior.
33-
# https://github.com/jazzband/django-redis#memcached-exceptions-behavior
34-
"IGNORE_EXCEPTIONS": True,
35-
},
26+
REDIS_URL = env("REDIS_URL", default="")
27+
28+
if REDIS_URL:
29+
CACHES = {
30+
"default": {
31+
"BACKEND": "django_redis.cache.RedisCache",
32+
"LOCATION": REDIS_URL,
33+
"OPTIONS": {
34+
"CLIENT_CLASS": "django_redis.client.DefaultClient",
35+
# Mimicing memcache behavior.
36+
# https://github.com/jazzband/django-redis#memcached-exceptions-behavior
37+
"IGNORE_EXCEPTIONS": True,
38+
},
39+
}
40+
}
41+
else:
42+
CACHES = {
43+
"default": {
44+
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
45+
"LOCATION": "",
46+
}
3647
}
37-
}
3848

3949
# SECURITY
4050
# ------------------------------------------------------------------------------

0 commit comments

Comments
 (0)