diff --git a/config/settings/development.py b/config/settings/development.py index b31c6c5f..d0d261b9 100644 --- a/config/settings/development.py +++ b/config/settings/development.py @@ -32,6 +32,15 @@ LOGGING["loggers"]["ethicalads_ext"]["level"] = "DEBUG" +# Cache +# https://docs.djangoproject.com/en/dev/topics/cache/ +# https://github.com/jazzband/django-redis +# -------------------------------------------------------------------------- +# Use the Redis cache in development if the REDIS_URL env var is set +if env("REDIS_URL", default=None): + CACHES["default"] = env.cache("REDIS_URL") + + # Celery settings for asynchronous tasks # http://docs.celeryproject.org # -------------------------------------------------------------------------- diff --git a/config/settings/production.py b/config/settings/production.py index ebb2bbbb..ebbf6783 100644 --- a/config/settings/production.py +++ b/config/settings/production.py @@ -64,7 +64,7 @@ # Cache # https://docs.djangoproject.com/en/dev/topics/cache/ -# https://niwinz.github.io/django-redis/ +# https://github.com/jazzband/django-redis # -------------------------------------------------------------------------- CACHES["default"] = env.cache("REDIS_URL") diff --git a/config/settings/testing.py b/config/settings/testing.py index ff7cb1dc..365e9cae 100644 --- a/config/settings/testing.py +++ b/config/settings/testing.py @@ -42,6 +42,12 @@ }, } +# Always use in-memory cache for testing +CACHES["default"] = { + "BACKEND": "django.core.cache.backends.locmem.LocMemCache", + "LOCATION": "", +} + # Celery should be always eager - there's no distributed celery workers in test CELERY_TASK_ALWAYS_EAGER = True diff --git a/requirements/production.in b/requirements/production.in index 1efc3c35..364755c9 100644 --- a/requirements/production.in +++ b/requirements/production.in @@ -11,7 +11,9 @@ psycopg[binary,pool] django-anymail # Redis (cache) -django-redis +# Hiredis is a faster Redis client implementation in C +# https://github.com/jazzband/django-redis?tab=readme-ov-file#pluggable-parsers +django-redis[hiredis] # Upload files to cloud storage (Azure) django-storages[azure] diff --git a/requirements/production.txt b/requirements/production.txt index c7ce57a7..26511af3 100644 --- a/requirements/production.txt +++ b/requirements/production.txt @@ -100,7 +100,7 @@ django-extensions==4.1 # via -r base.in django-ratelimit==3.0.1 # via -r base.in -django-redis==6.0.0 +django-redis[hiredis]==6.0.0 # via -r production.in django-simple-history==3.10.1 # via -r base.in @@ -122,6 +122,8 @@ geoip2==5.1.0 # via -r base.in gunicorn==23.0.0 # via -r production.in +hiredis==3.3.0 + # via redis idna==3.11 # via # requests @@ -172,7 +174,7 @@ pytz==2025.2 # via -r base.in qrcode==8.2 # via django-allauth -redis==5.3.1 +redis[hiredis]==5.3.1 # via # celery # django-redis