From d144d1cc7a7d78023b464f4628c7520251320256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20M=C3=BCnch?= Date: Sun, 9 Jan 2022 18:27:03 +0100 Subject: [PATCH] remove etag and last modified caching and disable it in backend settings --- coinmanager/coinc/cache.py | 52 ------------------- coinmanager/coinc/views.py | 6 --- .../coinmanager/production_settings.py | 2 +- 3 files changed, 1 insertion(+), 59 deletions(-) delete mode 100644 coinmanager/coinc/cache.py diff --git a/coinmanager/coinc/cache.py b/coinmanager/coinc/cache.py deleted file mode 100644 index 503a829..0000000 --- a/coinmanager/coinc/cache.py +++ /dev/null @@ -1,52 +0,0 @@ -# encoding: utf-8 -# -# Copyright (C) 2020 willipink.eu -# Author Moritz Münch moritzmuench@mailbox.org -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - - - -from django.core.cache import cache -from django.http import Http404 - -from .models import Coin - - -def get_last_modified_coin(request): - return cache.get('last_modified_coin', set_last_modified_coin()) - - -def set_last_modified_coin(): - ''' set and return the datetime of the last coin added ''' - try: - last_modified = Coin.objects.latest('date_modified').date_modified - except Coin.DoesNotExist: - raise Http404(f'Das Land existiert nicht') - cache.set('last_modified_coin', last_modified) - return last_modified - - -def get_last_modified_country(request, name_iso): - return cache.get(f'last_modified_{name_iso}', set_last_modified_country(name_iso)) - - -def set_last_modified_country(name_iso): - ''' return the datetime of the last coin added to a country ''' - try: - last_modified = Coin.objects.filter(country=name_iso).latest('date_modified').date_modified - except Coin.DoesNotExist: - raise Http404(f'Das Land "{name_iso}" existiert nicht') - cache.set(f'last_modified_{name_iso}', last_modified) - return last_modified diff --git a/coinmanager/coinc/views.py b/coinmanager/coinc/views.py index bc88e2b..5363065 100644 --- a/coinmanager/coinc/views.py +++ b/coinmanager/coinc/views.py @@ -28,13 +28,10 @@ from django.template.defaultfilters import register from django.views.decorators.http import condition from django.utils.datastructures import MultiValueDictKeyError -from .cache import (get_last_modified_coin, set_last_modified_coin, - get_last_modified_country, set_last_modified_country) from .models import Country, Stamp, Coin, User from .helper import total_coin_sum, coin_sum_of_ -@condition(last_modified_func=get_last_modified_coin) def index(request): ''' index view ''' @@ -55,7 +52,6 @@ def index(request): return HttpResponse(template.render(context, request)) -@condition(last_modified_func=get_last_modified_country) def detail_country(request, name_iso): ''' wrapper_view for a *single* country ''' @@ -370,8 +366,6 @@ def add_coin(request, country, year, value): in_collector = ec, exists = exists) - set_last_modified_coin() - set_last_modified_country(country.name_iso) return response() diff --git a/coinmanager/coinmanager/production_settings.py b/coinmanager/coinmanager/production_settings.py index 2f2acdf..58b6a86 100644 --- a/coinmanager/coinmanager/production_settings.py +++ b/coinmanager/coinmanager/production_settings.py @@ -48,7 +48,7 @@ MIDDLEWARE = [ 'django.middleware.common.CommonMiddleware', # 'django.middleware.cache.FetchFromCacheMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', - 'django.middleware.http.ConditionalGetMiddleware', +# 'django.middleware.http.ConditionalGetMiddleware', # set 'ETag' and 'Last Modified' headers 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware',