Skip to content

Commit

Permalink
Add Cache-Control header for thumbnails
Browse files Browse the repository at this point in the history
This drastically optimizes admin interface loading by telling the browser to cache thumbnails. The max-age recommendation is 1 year according to rfc2616
Closes the-paperless-project#411
  • Loading branch information
CkuT committed Jan 21, 2019
1 parent 0256dcb commit 7986893
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/documents/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.views.generic import DetailView, FormView, TemplateView
from django_filters.rest_framework import DjangoFilterBackend
from django.conf import settings
from django.utils import cache

from paperless.db import GnuPG
from paperless.mixins import SessionOrBasicAuthMixin
Expand Down Expand Up @@ -56,10 +57,12 @@ def render_to_response(self, context, **response_kwargs):
}

if self.kwargs["kind"] == "thumb":
return HttpResponse(
response = HttpResponse(
self._get_raw_data(self.object.thumbnail_file),
content_type=content_types[Document.TYPE_PNG]
)
cache.patch_cache_control(response, max_age=31536000, private=True)
return response

response = HttpResponse(
self._get_raw_data(self.object.source_file),
Expand Down

0 comments on commit 7986893

Please sign in to comment.