فهرست منبع

修改了appset/query这个接口,缓存方式访问数据库表,缓存时间为3600秒后刷新一次

pengzhibo168 5 سال پیش
والد
کامیت
b404bfb35d
1فایلهای تغییر یافته به همراه44 افزوده شده و 23 حذف شده
  1. 44 23
      Controller/AppSetController.py

+ 44 - 23
Controller/AppSetController.py

@@ -11,11 +11,12 @@
 @file: AppSetController.py
 @Contact: chanjunkai@163.com
 """
-
+from Model.models import versionControlModel
 from django.views.generic.base import View
-
+from cacheout import LFUCache
+import time,json
 from Object.ResponseObject import ResponseObject
-
+cache = LFUCache()
 
 class AppSetView(View):
     def get(self, request, *args, **kwargs):
@@ -37,27 +38,47 @@ class AppSetView(View):
             return self.do_query(request_dict, response)
         else:
             return response.json(414)
-
+    # 查询
     def do_query(self, request_dict, response):
         appBundleId = request_dict.get('appBundleId', None)
         if not appBundleId:
             return response.json(444,'appBundleId')
-        res = {}
-        res['grade'] = 1
-        #     # 用户帮助
-        res['usingHelp'] = 0
-        #     # AP添加方式
-        res['apAdd'] = 1
-        #     # AP工具
-        res['apTool'] = 1
-        #     # 广告模块
-        res['ad_module'] = {
-            "time": 0,
-            "ad_path": [
-                "https://test.dvema.com/web/static/image/default_ad1",
-                "https://test.dvema.com/web/static/image/default_ad2",
-                "https://test.dvema.com/web/static/image/default_ad3",
-            ]
-        }
-        res['init_img'] = 'https://test.dvema.com/web/static/image/default_start'
-        return response.json(0, res)
+        if cache.get(appBundleId)==None:
+            print('添加到缓存')
+            # 查数据库
+            sm_qs = versionControlModel.objects.filter(appBundleId=appBundleId)
+            count = sm_qs.count()
+            if count > 0:
+                sm_qs = sm_qs.values( 'id', 'appBundleId', 'content', 'addTime', 'updTime')
+                # 添加到缓存,缓存时间为3600秒------指的是一个钟后再次访问,就会刷新缓存一次
+                cache.set(appBundleId, {'content': list(sm_qs)}, ttl=3600)
+                # return response.json(0,list(sm_qs))
+                # 返回固定值
+                return response.json(0, json.loads(list(sm_qs)[0]['content']))
+            else:
+                return response.json(0)
+        else:
+            # print('去缓存找')
+            # return response.json(0, cache.get(appBundleId).get('content'))
+            # 返回固定值
+            return response.json(0, json.loads(cache.get(appBundleId).get('content')[0]['content']))
+
+        # res = {}
+        # res['grade'] = 1
+        # #     # 用户帮助
+        # res['usingHelp'] = 0
+        # #     # AP添加方式
+        # res['apAdd'] = 1
+        # #     # AP工具
+        # res['apTool'] = 1
+        # #     # 广告模块
+        # res['ad_module'] = {
+        #     "time": 0,
+        #     "ad_path": [
+        #         "https://test.dvema.com/web/static/image/default_ad1",
+        #         "https://test.dvema.com/web/static/image/default_ad2",
+        #         "https://test.dvema.com/web/static/image/default_ad3",
+        #     ]
+        # }
+        # res['init_img'] = 'https://test.dvema.com/web/static/image/default_start'
+        # return response.json(0, res)