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):