Increase the max age, create separate option in config for it (CACHE_IMAGE_MAX_AGE). Issue #50

This commit is contained in:
Oliver Falk
2019-03-08 13:49:09 +01:00
parent 9b924fff57
commit 166582bc9d
2 changed files with 11 additions and 8 deletions

View File

@@ -187,3 +187,5 @@ CACHES = {
], ],
} }
} }
CACHE_IMAGES_MAX_AGE = 24 * 60 * 60

View File

@@ -22,6 +22,7 @@ import pagan
from robohash import Robohash from robohash import Robohash
from ivatar.settings import AVATAR_MAX_SIZE, JPEG_QUALITY, DEFAULT_AVATAR_SIZE from ivatar.settings import AVATAR_MAX_SIZE, JPEG_QUALITY, DEFAULT_AVATAR_SIZE
from ivatar.settings import CACHE_IMAGES_MAX_AGE
from . ivataraccount.models import ConfirmedEmail, ConfirmedOpenId from . ivataraccount.models import ConfirmedEmail, ConfirmedOpenId
from . ivataraccount.models import pil_format, file_format from . ivataraccount.models import pil_format, file_format
@@ -150,7 +151,7 @@ class AvatarImageView(TemplateView):
response = HttpResponse( response = HttpResponse(
data, data,
content_type='image/png') content_type='image/png')
response['Cache-Control'] = 'max-age=300' response['Cache-Control'] = 'max-age=%i' % CACHE_IMAGES_MAX_AGE
return response return response
if str(default) == 'robohash': if str(default) == 'robohash':
@@ -165,7 +166,7 @@ class AvatarImageView(TemplateView):
response = HttpResponse( response = HttpResponse(
data, data,
content_type='image/png') content_type='image/png')
response['Cache-Control'] = 'max-age=300' response['Cache-Control'] = 'max-age=%i' % CACHE_IMAGES_MAX_AGE
return response return response
if str(default) == 'retro': if str(default) == 'retro':
@@ -178,7 +179,7 @@ class AvatarImageView(TemplateView):
response = HttpResponse( response = HttpResponse(
data, data,
content_type='image/png') content_type='image/png')
response['Cache-Control'] = 'max-age=300' response['Cache-Control'] = 'max-age=%i' % CACHE_IMAGES_MAX_AGE
return response return response
if str(default) == 'pagan': if str(default) == 'pagan':
@@ -190,7 +191,7 @@ class AvatarImageView(TemplateView):
response = HttpResponse( response = HttpResponse(
data, data,
content_type='image/png') content_type='image/png')
response['Cache-Control'] = 'max-age=300' response['Cache-Control'] = 'max-age=%i' % CACHE_IMAGES_MAX_AGE
return response return response
if str(default) == 'identicon': if str(default) == 'identicon':
@@ -204,7 +205,7 @@ class AvatarImageView(TemplateView):
response = HttpResponse( response = HttpResponse(
data, data,
content_type='image/png') content_type='image/png')
response['Cache-Control'] = 'max-age=300' response['Cache-Control'] = 'max-age=%i' % CACHE_IMAGES_MAX_AGE
return response return response
if str(default) == 'mm' or str(default) == 'mp': if str(default) == 'mm' or str(default) == 'mp':
@@ -244,7 +245,7 @@ class AvatarImageView(TemplateView):
response = HttpResponse( response = HttpResponse(
data, data,
content_type='image/%s' % imgformat) content_type='image/%s' % imgformat)
response['Cache-Control'] = 'max-age=300' response['Cache-Control'] = 'max-age=%i' % CACHE_IMAGES_MAX_AGE
return response return response
class GravatarProxyView(View): class GravatarProxyView(View):
@@ -317,7 +318,7 @@ class GravatarProxyView(View):
response = HttpResponse( response = HttpResponse(
data.read(), data.read(),
content_type='image/%s' % file_format(img.format)) content_type='image/%s' % file_format(img.format))
response['Cache-Control'] = 'max-age=300' response['Cache-Control'] = 'max-age=%i' % CACHE_IMAGES_MAX_AGE
return response return response
except ValueError as exc: except ValueError as exc: