mirror of
https://github.com/inventree/InvenTree.git
synced 2025-08-07 12:22:11 +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:
@@ -307,6 +307,7 @@ The following cache settings are available:
|
|||||||
| INVENTREE_CACHE_ENABLED | cache.enabled | Enable redis caching | False |
|
| INVENTREE_CACHE_ENABLED | cache.enabled | Enable redis caching | False |
|
||||||
| INVENTREE_CACHE_HOST | cache.host | Cache server host | *Not specified* |
|
| INVENTREE_CACHE_HOST | cache.host | Cache server host | *Not specified* |
|
||||||
| INVENTREE_CACHE_PORT | cache.port | Cache server port | 6379 |
|
| 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_CONNECT_TIMEOUT | cache.connect_timeout | Cache connection timeout (seconds) | 3 |
|
||||||
| INVENTREE_CACHE_TIMEOUT | cache.timeout | Cache timeout (seconds) | 3 |
|
| INVENTREE_CACHE_TIMEOUT | cache.timeout | Cache timeout (seconds) | 3 |
|
||||||
| INVENTREE_CACHE_TCP_KEEPALIVE | cache.tcp_keepalive | Cache TCP keepalive | True |
|
| INVENTREE_CACHE_TCP_KEEPALIVE | cache.tcp_keepalive | Cache TCP keepalive | True |
|
||||||
|
@@ -37,6 +37,11 @@ def cache_port() -> int:
|
|||||||
return cache_setting('port', '6379', typecast=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:
|
def is_global_cache_enabled() -> bool:
|
||||||
"""Check if the global cache is enabled.
|
"""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.
|
A dictionary containing the cache configuration options.
|
||||||
"""
|
"""
|
||||||
if global_cache:
|
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 {
|
return {
|
||||||
'BACKEND': 'django_redis.cache.RedisCache',
|
'BACKEND': 'django_redis.cache.RedisCache',
|
||||||
'LOCATION': f'redis://{cache_host()}:{cache_port()}/0',
|
'LOCATION': redis_url,
|
||||||
'OPTIONS': {
|
'OPTIONS': {
|
||||||
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
|
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
|
||||||
'SOCKET_CONNECT_TIMEOUT': cache_setting(
|
'SOCKET_CONNECT_TIMEOUT': cache_setting(
|
||||||
|
Reference in New Issue
Block a user