From dfa576fd62ba3ab398422a99f2c2eac88674c058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Sat, 2 Jan 2021 13:29:19 +0100 Subject: [PATCH] cache image files for 6 hours --- sdbs_pile/pile/urls.py | 3 ++- sdbs_pile/settings.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/sdbs_pile/pile/urls.py b/sdbs_pile/pile/urls.py index 32d2a19..d227ab4 100644 --- a/sdbs_pile/pile/urls.py +++ b/sdbs_pile/pile/urls.py @@ -1,4 +1,5 @@ from django.urls import path +from django.views.decorators.cache import cache_page from . import views from .views import IPFSView, ExternalLinkView @@ -10,7 +11,7 @@ urlpatterns = [ path('item/', views.DocumentView.as_view(), name='document'), path('label/', views.LabelView.as_view(), name='label'), path('retrieve/', views.DocumentWithLabelView.as_view(), name='retrieve'), - path('image/', views.BrandedImageView.as_view(), name='image'), + path('image/', cache_page(60 * 60 * 6)(views.BrandedImageView.as_view()), name='image'), path('feed', views.RecentlyUploadedFeed()), path('api/external_links', ExternalLinkView), path('api/ipfs_cids', IPFSView) diff --git a/sdbs_pile/settings.py b/sdbs_pile/settings.py index dc6fd22..c54047f 100644 --- a/sdbs_pile/settings.py +++ b/sdbs_pile/settings.py @@ -24,10 +24,24 @@ SECRET_KEY = os.getenv("SECRET_KEY") if os.getenv("DEV"): DEBUG = True ALLOWED_HOSTS = [] + + CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.dummy.DummyCache', + } + } + else: DEBUG = False ALLOWED_HOSTS = ["pile.sdbs.cz"] + CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', + 'LOCATION': '/var/tmp/pile_cache', + } + } + STATIC_PILE = bool(os.getenv("STATIC")) # Application definition