From 23909680293641aa2cb22c77885150dc2f29b56e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9DNyymix=E2=80=9D?= Date: Mon, 14 Apr 2025 10:22:52 +0300 Subject: [PATCH] Add django-redis cache --- config/settings.py | 45 ++++++++++++++++++++++++--------------------- requirements.txt | 1 + 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/config/settings.py b/config/settings.py index 2fbb948..224a8b6 100644 --- a/config/settings.py +++ b/config/settings.py @@ -1,24 +1,8 @@ -""" -Django settings for config project. - -Generated by 'django-admin startproject' using Django 5.1.4. - -For more information on this file, see -https://docs.djangoproject.com/en/5.1/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/5.1/ref/settings/ -""" - from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent - -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/ - # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'django-insecure-$m!a$rjih3i64n8&t3km0u--k0_ij5-a6t!(n_nbz1$)$%0lqn' @@ -27,9 +11,9 @@ DEBUG = True ALLOWED_HOSTS = [] +INTERNAL_IPS = ['localhost', '127.0.0.1',] # Application definition - INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', @@ -114,7 +98,9 @@ TIME_ZONE = 'UTC' USE_I18N = True -USE_TZ = True +#USE_TZ = True +USE_TZ = False + # Static files (CSS, JavaScript, Images) @@ -141,8 +127,25 @@ MEDIA_ROOT = BASE_DIR / 'media' DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' -# Session lifetime 1 year -SESSION_COOKIE_AGE = 31556000 +# Sessions +SESSION_COOKIE_AGE = 60 * 60 * 24 * 365 * 5 # 5 vuotta +SESSION_EXPIRE_AT_BROWSER_CLOSE = False +SESSION_COOKIE_SECURE = True +SESSION_COOKIE_SAMESITE = 'Lax' + +# Sessio backend: cache + fallback tietokantaan +SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db' + +# Redis cache +CACHES = { + "default": { + "BACKEND": "django_redis.cache.RedisCache", + "LOCATION": "redis://127.0.0.1:6379/1", + "OPTIONS": { + "CLIENT_CLASS": "django_redis.client.DefaultClient", + } + } +} # Gotify @@ -195,4 +198,4 @@ LOGGING = { try: from .local_settings import * except ImportError: - pass + pass \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 4377fc7..a370a7c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ Django==5.1.7 django_cleanup==9.0.0 django_imagekit==5.0.0 +django-redis==5.4.0 Pillow==11.1.0 pytz==2025.2 Requests==2.32.3