added redis as cache backend

This commit is contained in:
vabene1111
2025-07-11 21:51:54 +02:00
parent 8c1769458d
commit 8c849a1077
4 changed files with 22 additions and 1 deletions

View File

@@ -20,7 +20,7 @@
<div class="container">
<h1 >{% trans 'System' %}</h1>
<h1>{% trans 'System' %}</h1>
{% blocktrans %}
Tandoor Recipes is an open source free software application. It can be found on
<a href="https://github.com/TandoorRecipes/recipes">GitHub</a>.
@@ -213,6 +213,14 @@
{% endfor %}
</table>
{% endif %}
<h4 class="mt-3">Cache Test</h4>
On first load this should be None, on second load it should be the time of the first load. Expiration is set to 10 seconds after that it should be None again. <br/>
{% if cache_response %}
<span class="badge text-bg-success">Cache entry from {{ cache_response|date:" d m Y H:i:s" }}</span>
{% else %}
<span class="badge text-bg-info">No cache entry before load</span>
{% endif %}
<h4 class="mt-3">Debug</h4>
<textarea class="form-control" rows="20">
Gunicorn Media: {{ gunicorn_media }}

View File

@@ -12,6 +12,7 @@ from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import Group
from django.contrib.auth.password_validation import validate_password
from django.core.cache import caches
from django.core.exceptions import ValidationError
from django.core.management import call_command
from django.db import models
@@ -242,6 +243,10 @@ def system(request):
space_stats.append(r.zscore(f'api:space-request-count:{d}', s))
api_space_stats.append(space_stats)
cache_response = caches['default'].get(f'system_view_test_cache_entry', None)
if not cache_response:
caches['default'].set(f'system_view_test_cache_entry', datetime.now(), 10)
return render(
request, 'system.html', {
'gunicorn_media': settings.GUNICORN_MEDIA,
@@ -256,6 +261,7 @@ def system(request):
'orphans': orphans,
'migration_info': migration_info,
'missing_migration': missing_migration,
'cache_response': cache_response,
})

View File

@@ -521,6 +521,12 @@ CACHES = {
}
}
if REDIS_HOST:
CACHES['default'] = {
'BACKEND': 'django.core.cache.backends.redis.RedisCache',
'LOCATION': f'redis://{REDIS_USERNAME}:{REDIS_PASSWORD}@{REDIS_HOST}:{REDIS_PORT}',
}
# Vue webpack settings
VUE_DIR = os.path.join(BASE_DIR, 'vue')

View File

@@ -44,6 +44,7 @@ pytubefix==9.2.2
aiohttp==3.10.11
inflection==0.5.1
redis==5.2.1
hiredis==3.2.1
requests-oauthlib==2.0.0
pyjwt==2.10.1
python3-openid==3.2.0