rename caching functions on server

This commit is contained in:
Moritz Münch 2021-10-04 10:58:16 +00:00
parent 0561aa54f4
commit d5429f0c2b
2 changed files with 7 additions and 7 deletions

View File

@ -27,17 +27,17 @@ from django.http import Http404
from .models import Coin from .models import Coin
def get_last_modified_index(request): def get_last_modified_coin(request):
return cache.get(f'last_modified_index', set_last_modified_index()) return cache.get('last_modified_coin', set_last_modified_coin())
def set_last_modified_index(): def set_last_modified_coin():
''' set and return the datetime of the last coin added ''' ''' set and return the datetime of the last coin added '''
try: try:
last_modified = Coin.objects.latest('date_modified').date_modified last_modified = Coin.objects.latest('date_modified').date_modified
except Coin.DoesNotExist: except Coin.DoesNotExist:
raise Http404(f'Das Land "{name_iso}" existiert nicht') raise Http404(f'Das Land "{name_iso}" existiert nicht')
cache.set(f'last_modified_index', last_modified) cache.set('last_modified_coin', last_modified)
return last_modified return last_modified

View File

@ -27,13 +27,13 @@ from django.template import loader
from django.template.defaultfilters import register from django.template.defaultfilters import register
from django.views.decorators.http import condition from django.views.decorators.http import condition
from .cache import (get_last_modified_index, set_last_modified_index, from .cache import (get_last_modified_coin, set_last_modified_coin,
get_last_modified_country, set_last_modified_country) 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_index) @condition(last_modified_func=get_last_modified_coin)
def index(request): def index(request):
''' index view ''' ''' index view '''
@ -378,7 +378,7 @@ def add_coin(request):
in_collector = ec, in_collector = ec,
exists = exists) exists = exists)
set_last_modified_index() set_last_modified_coin()
set_last_modified_country(country.name_iso) set_last_modified_country(country.name_iso)
return response() return response()