From 52cd76eb9349737ec4729b30970e1a2a29533146 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 29 Jan 2026 16:11:55 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7(backend)=20customize=20cache=20con?= =?UTF-8?q?fig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We want to split the cache config between the app cache and the session cache. In the app cache, the default one, we allow to configure a prefix. By default this prefix is a fixed string so the cache will be never revoked because it is changing but it allow every instance to implement its own strategy like prefixing the keyx cache with a timestamp. To not impact session, the session cache is splitted in the settings. --- docs/env.md | 2 +- src/backend/impress/settings.py | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/docs/env.md b/docs/env.md index 186cfb30..1ce94dcd 100644 --- a/docs/env.md +++ b/docs/env.md @@ -23,7 +23,7 @@ These are the environment variables you can set for the `impress-backend` contai | AWS_S3_SECRET_ACCESS_KEY | Access key for s3 endpoint | | | AWS_STORAGE_BUCKET_NAME | Bucket name for s3 endpoint | impress-media-storage | | CACHES_DEFAULT_TIMEOUT | Cache default timeout | 30 | -| CACHES_KEY_PREFIX | The prefix used to every cache keys. | docs | +| CACHES_DEFAULT_KEY_PREFIX | The prefix used to every cache keys. | docs | | COLLABORATION_API_URL | Collaboration api host | | | COLLABORATION_SERVER_SECRET | Collaboration api secret | | | COLLABORATION_WS_NOT_CONNECTED_READY_ONLY | Users not connected to the collaboration server cannot edit | false | diff --git a/src/backend/impress/settings.py b/src/backend/impress/settings.py index ffee8d64..80d3a149 100755 --- a/src/backend/impress/settings.py +++ b/src/backend/impress/settings.py @@ -1083,6 +1083,7 @@ class Production(Base): # Modern browsers require to have the `secure` attribute on cookies with `Samesite=none` CSRF_COOKIE_SECURE = True SESSION_COOKIE_SECURE = True + SESSION_CACHE_ALIAS = "session" # Privacy SECURE_REFERRER_POLICY = "same-origin" @@ -1090,11 +1091,12 @@ class Production(Base): # Conversion API: Always verify SSL in production CONVERSION_API_SECURE = True + # Cache CACHES = { "default": { "BACKEND": "django_redis.cache.RedisCache", "LOCATION": values.Value( - "redis://redis:6379/1", + "redis://redis:6379/0", environ_name="REDIS_URL", environ_prefix=None, ), @@ -1108,10 +1110,26 @@ class Production(Base): }, "KEY_PREFIX": values.Value( "docs", - environ_name="CACHES_KEY_PREFIX", + environ_name="CACHES_DEFAULT_KEY_PREFIX", environ_prefix=None, ), }, + "session": { + "BACKEND": "django_redis.cache.RedisCache", + "LOCATION": values.Value( + "redis://redis:6379/0", + environ_name="REDIS_URL", + environ_prefix=None, + ), + "TIMEOUT": values.IntegerValue( + 30, # timeout in seconds + environ_name="CACHES_SESSION_TIMEOUT", + environ_prefix=None, + ), + "OPTIONS": { + "CLIENT_CLASS": "django_redis.client.DefaultClient", + }, + }, }