remove etag and last modified caching and disable it in backend settings
This commit is contained in:
parent
1b988f03c7
commit
d144d1cc7a
@ -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 <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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
|
|
@ -28,13 +28,10 @@ from django.template.defaultfilters import register
|
|||||||
from django.views.decorators.http import condition
|
from django.views.decorators.http import condition
|
||||||
from django.utils.datastructures import MultiValueDictKeyError
|
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 .models import Country, Stamp, Coin, User
|
||||||
from .helper import total_coin_sum, coin_sum_of_
|
from .helper import total_coin_sum, coin_sum_of_
|
||||||
|
|
||||||
|
|
||||||
@condition(last_modified_func=get_last_modified_coin)
|
|
||||||
def index(request):
|
def index(request):
|
||||||
''' index view '''
|
''' index view '''
|
||||||
|
|
||||||
@ -55,7 +52,6 @@ def index(request):
|
|||||||
return HttpResponse(template.render(context, request))
|
return HttpResponse(template.render(context, request))
|
||||||
|
|
||||||
|
|
||||||
@condition(last_modified_func=get_last_modified_country)
|
|
||||||
def detail_country(request, name_iso):
|
def detail_country(request, name_iso):
|
||||||
''' wrapper_view for a *single* country '''
|
''' wrapper_view for a *single* country '''
|
||||||
|
|
||||||
@ -370,8 +366,6 @@ def add_coin(request, country, year, value):
|
|||||||
in_collector = ec,
|
in_collector = ec,
|
||||||
exists = exists)
|
exists = exists)
|
||||||
|
|
||||||
set_last_modified_coin()
|
|
||||||
set_last_modified_country(country.name_iso)
|
|
||||||
return response()
|
return response()
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ MIDDLEWARE = [
|
|||||||
'django.middleware.common.CommonMiddleware',
|
'django.middleware.common.CommonMiddleware',
|
||||||
# 'django.middleware.cache.FetchFromCacheMiddleware',
|
# 'django.middleware.cache.FetchFromCacheMiddleware',
|
||||||
'django.middleware.csrf.CsrfViewMiddleware',
|
'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.auth.middleware.AuthenticationMiddleware',
|
||||||
'django.contrib.messages.middleware.MessageMiddleware',
|
'django.contrib.messages.middleware.MessageMiddleware',
|
||||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user