2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-08-06 12:01:41 +00:00

feat: Add support for cache password in Redis configuration (#10107)

* feat(cache): Add support for cache password in Redis configuration

* Add cache password configuration option to documentation

* Fix the complaints from CI checks
This commit is contained in:
Daniel Glaser
2025-08-01 02:36:02 +02:00
committed by GitHub
parent a79ab40f5e
commit b9a8ace614
2 changed files with 15 additions and 1 deletions

View File

@@ -307,6 +307,7 @@ The following cache settings are available:
| INVENTREE_CACHE_ENABLED | cache.enabled | Enable redis caching | False |
| INVENTREE_CACHE_HOST | cache.host | Cache server host | *Not specified* |
| INVENTREE_CACHE_PORT | cache.port | Cache server port | 6379 |
| INVENTREE_CACHE_PASSWORD | cache.password | Cache server password | none |
| INVENTREE_CACHE_CONNECT_TIMEOUT | cache.connect_timeout | Cache connection timeout (seconds) | 3 |
| INVENTREE_CACHE_TIMEOUT | cache.timeout | Cache timeout (seconds) | 3 |
| INVENTREE_CACHE_TCP_KEEPALIVE | cache.tcp_keepalive | Cache TCP keepalive | True |

View File

@@ -37,6 +37,11 @@ def cache_port() -> int:
return cache_setting('port', '6379', typecast=int)
def cache_password():
"""Return the cache password."""
return cache_setting('password', None)
def is_global_cache_enabled() -> bool:
"""Check if the global cache is enabled.
@@ -77,9 +82,17 @@ def get_cache_config(global_cache: bool) -> dict:
A dictionary containing the cache configuration options.
"""
if global_cache:
# Build Redis URL with optional password
password = cache_password()
if password:
redis_url = f'redis://:{password}@{cache_host()}:{cache_port()}/0'
else:
redis_url = f'redis://{cache_host()}:{cache_port()}/0'
return {
'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': f'redis://{cache_host()}:{cache_port()}/0',
'LOCATION': redis_url,
'OPTIONS': {
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
'SOCKET_CONNECT_TIMEOUT': cache_setting(