mirror of
https://git.linux-kernel.at/oliver/ivatar.git
synced 2025-11-11 18:56:23 +00:00
Add setting to easily be able to disable the response caching
This commit is contained in:
@@ -194,5 +194,7 @@ CACHES = {
|
||||
}
|
||||
|
||||
# This is 5 minutes caching for generated/resized images,
|
||||
# so the sites don't hit ivatar so much
|
||||
# so the sites don't hit ivatar so much - it's what's set in the HTTP header
|
||||
CACHE_IMAGES_MAX_AGE = 5 * 60
|
||||
|
||||
CACHE_RESPONSE = False
|
||||
|
||||
@@ -23,7 +23,7 @@ from pydenticon5 import Pydenticon5
|
||||
import pagan
|
||||
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, CACHE_RESPONSE
|
||||
from ivatar.settings import CACHE_IMAGES_MAX_AGE
|
||||
from . ivataraccount.models import ConfirmedEmail, ConfirmedOpenId
|
||||
from . ivataraccount.models import pil_format, file_format
|
||||
@@ -57,6 +57,7 @@ def get_size(request, size=DEFAULT_AVATAR_SIZE):
|
||||
|
||||
class CachingHttpResponse(HttpResponse):
|
||||
def __init__(self, uri, content=b'', content_type=None, status=200, reason=None, charset=None):
|
||||
if CACHE_RESPONSE:
|
||||
caches['filesystem'].set(uri, {
|
||||
'content': content,
|
||||
'content_type': content_type,
|
||||
@@ -92,6 +93,7 @@ class AvatarImageView(TemplateView):
|
||||
uri = request.build_absolute_uri()
|
||||
|
||||
# Check the cache first
|
||||
if CACHE_RESPONSE:
|
||||
centry = caches['filesystem'].get(uri)
|
||||
if centry:
|
||||
# For DEBUG purpose only print('Cached entry for %s' % uri)
|
||||
|
||||
Reference in New Issue
Block a user