From 75642532e97b7cf1c8aa72085da0757bf003ba05 Mon Sep 17 00:00:00 2001 From: RogerWork Date: Tue, 19 Dec 2023 16:51:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E5=8F=91=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dingxin_toolbox_drf/settings.py | 2 +- update/views.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/dingxin_toolbox_drf/settings.py b/dingxin_toolbox_drf/settings.py index e442e00..7fde102 100644 --- a/dingxin_toolbox_drf/settings.py +++ b/dingxin_toolbox_drf/settings.py @@ -102,7 +102,7 @@ CACHES = { } REST_FRAMEWORK_EXTENSIONS = { - 'DEFAULT_CACHE_RESPONSE_TIMEOUT': 60 * 5, # 缓存时间 + 'DEFAULT_CACHE_RESPONSE_TIMEOUT': 60*1, # 缓存时间 'DEFAULT_USE_CACHE': 'default', # 缓存存储 'DEFAULT_OBJECT_CACHE_KEY_FUNC': 'rest_framework_extensions.utils.default_object_cache_key_func', 'DEFAULT_LIST_CACHE_KEY_FUNC': 'rest_framework_extensions.utils.default_list_cache_key_func', diff --git a/update/views.py b/update/views.py index 1833889..53d5e41 100644 --- a/update/views.py +++ b/update/views.py @@ -11,6 +11,7 @@ from django.views.decorators.cache import cache_page from django_filters.rest_framework import DjangoFilterBackend from django.core.cache import cache from update.utils.get_version import GetVersion +from rest_framework.decorators import action # CacheResponseMixin 一定要放第一位 @@ -32,6 +33,14 @@ class CinemaViewSet(CacheResponseMixin, viewsets.ModelViewSet): filterset_fields = ('ip',) GetVersion().main_process() + @action(methods=['get'], detail=False) + def refresh(self, request, *args, **kwargs): + GetVersion().main_process() + queryset = Cinema.objects.all() + serializer = self.get_serializer(instance=queryset, many=True) + return Response(serializer.data) + + # class CinemaSearchAPIView(APIView, CacheResponseMixin): # @method_decorator(cache_page(60 * 5)) # def get(self, request, *args, **kwargs):