From b93b29d06c7cab66eb0fb8babea90e66d2464482 Mon Sep 17 00:00:00 2001 From: Alexander-D-Karpov Date: Fri, 28 Jul 2023 20:03:19 +0300 Subject: [PATCH] fixed cache --- config/settings/base.py | 15 +++++++-------- config/settings/local.py | 10 ---------- config/urls.py | 9 +++++++-- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/config/settings/base.py b/config/settings/base.py index d7bf154..465fcee 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -54,17 +54,17 @@ # CACHES # ------------------------------------------------------------------------------ -CACHE_TTL = 60 * 1500 - -CACHES = {"default": env.cache("REDIS_CACHE")} +CACHES = {"default": env.cache_url("REDIS_CACHE")} +CACHE_MIDDLEWARE_KEY_PREFIX = "cache_middleware" +CACHE_MIDDLEWARE_SECONDS = 0 +CACHE_TTL = 60 * 10 SESSION_ENGINE = "django.contrib.sessions.backends.cache" SESSION_CACHE_ALIAS = "default" -CACHEOPS_DEFAULTS = {"timeout": 60 * 60} CACHEOPS = { "auth.user": {"ops": "get", "timeout": 60 * 15}, - "auth.*": {"ops": ("fetch", "get")}, - "auth.permission": {"ops": "all"}, - "*.*": {}, + "auth.*": {"ops": ("fetch", "get"), "timeout": 60 * 2}, + "blog.*": {"ops": ("fetch", "get"), "timeout": 15}, + "auth.permission": {"ops": "all", "timeout": 60 * 15}, } CACHEOPS_REDIS = env.str("REDIS_URL") @@ -271,7 +271,6 @@ "django.template.context_processors.tz", "django.contrib.messages.context_processors.messages", "akarpov.users.context_processors.allauth_settings", - "sekizai.context_processors.sekizai", ], }, } diff --git a/config/settings/local.py b/config/settings/local.py index 27ee0ef..a662eb7 100644 --- a/config/settings/local.py +++ b/config/settings/local.py @@ -14,16 +14,6 @@ ALLOWED_HOSTS = ["*"] CSRF_TRUSTED_ORIGINS = ["http://127.0.0.1", "https://*.akarpov.ru"] -# CACHES -# ------------------------------------------------------------------------------ -# https://docs.djangoproject.com/en/dev/ref/settings/#caches -CACHES = { - "default": { - "BACKEND": "django.core.cache.backends.locmem.LocMemCache", - "LOCATION": "", - } -} - # EMAIL # ------------------------------------------------------------------------------ # https://docs.djangoproject.com/en/dev/ref/settings/#email-host diff --git a/config/urls.py b/config/urls.py index b645c3e..f59f5d0 100644 --- a/config/urls.py +++ b/config/urls.py @@ -4,6 +4,7 @@ from django.contrib.sitemaps.views import sitemap from django.urls import include, path, re_path from django.views import defaults as default_views +from django.views.decorators.cache import cache_page from django.views.generic import TemplateView from drf_spectacular.views import ( SpectacularAPIView, @@ -16,7 +17,11 @@ from config.sitemaps import sitemaps urlpatterns = [ - path("home", TemplateView.as_view(template_name="pages/home.html"), name="home"), + path( + "home", + cache_page(600)(TemplateView.as_view(template_name="pages/home.html")), + name="home", + ), re_path(r"^robots\.txt", include("robots.urls")), path( "sitemap.xml", @@ -29,7 +34,7 @@ path(settings.ADMIN_URL, admin.site.urls), # User management path("users/", include("akarpov.users.urls", namespace="users")), - path("about", about_view), + path("about", cache_page(600)(about_view)), path("about/", include("akarpov.about.urls", namespace="about")), path("files/", include("akarpov.files.urls", namespace="files")), path("music/", include("akarpov.music.urls", namespace="music")),