增加自定义刷新发法

main
RogerWork 11 months ago
parent 30cd5eef5a
commit 75642532e9
  1. 2
      dingxin_toolbox_drf/settings.py
  2. 9
      update/views.py

@ -102,7 +102,7 @@ CACHES = {
} }
REST_FRAMEWORK_EXTENSIONS = { REST_FRAMEWORK_EXTENSIONS = {
'DEFAULT_CACHE_RESPONSE_TIMEOUT': 60 * 5, # 缓存时间 'DEFAULT_CACHE_RESPONSE_TIMEOUT': 60*1, # 缓存时间
'DEFAULT_USE_CACHE': 'default', # 缓存存储 'DEFAULT_USE_CACHE': 'default', # 缓存存储
'DEFAULT_OBJECT_CACHE_KEY_FUNC': 'rest_framework_extensions.utils.default_object_cache_key_func', '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', 'DEFAULT_LIST_CACHE_KEY_FUNC': 'rest_framework_extensions.utils.default_list_cache_key_func',

@ -11,6 +11,7 @@ from django.views.decorators.cache import cache_page
from django_filters.rest_framework import DjangoFilterBackend from django_filters.rest_framework import DjangoFilterBackend
from django.core.cache import cache from django.core.cache import cache
from update.utils.get_version import GetVersion from update.utils.get_version import GetVersion
from rest_framework.decorators import action
# CacheResponseMixin 一定要放第一位 # CacheResponseMixin 一定要放第一位
@ -32,6 +33,14 @@ class CinemaViewSet(CacheResponseMixin, viewsets.ModelViewSet):
filterset_fields = ('ip',) filterset_fields = ('ip',)
GetVersion().main_process() 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): # class CinemaSearchAPIView(APIView, CacheResponseMixin):
# @method_decorator(cache_page(60 * 5)) # @method_decorator(cache_page(60 * 5))
# def get(self, request, *args, **kwargs): # def get(self, request, *args, **kwargs):

Loading…
Cancel
Save