Skip to content

Commit

Permalink
Cache non changing views
Browse files Browse the repository at this point in the history
  • Loading branch information
derneuere committed Mar 30, 2024
1 parent bc03702 commit 7448007
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
)
from django.utils.decorators import method_decorator
from django.utils.encoding import iri_to_uri
from django.views.decorators.cache import cache_page
from django.views.decorators.csrf import ensure_csrf_cookie
from django.views.decorators.vary import vary_on_cookie
from django_q.tasks import AsyncTask
from drf_spectacular.utils import OpenApiParameter, OpenApiTypes, extend_schema
from rest_framework import viewsets
Expand Down Expand Up @@ -201,6 +203,7 @@ def get(self, request, format=None):


class ImageTagView(APIView):
@method_decorator(cache_page(60 * 60 * 2))
def get(self, request, format=None):
# Add an exception for the directory '/code'
subprocess.run(
Expand All @@ -219,6 +222,8 @@ def get(self, request, format=None):


class SearchTermExamples(APIView):
@method_decorator(vary_on_cookie)
@method_decorator(cache_page(60 * 60 * 2))
def get(self, request, format=None):
search_term_examples = get_search_term_examples(request.user)
return Response({"results": search_term_examples})
Expand Down

0 comments on commit 7448007

Please sign in to comment.