|
@@ -15,6 +15,7 @@ from django.views.generic.base import View
|
|
|
import Ansjer
|
|
|
from Ansjer.config import BASE_DIR, SERVER_TYPE, SERVER_DOMAIN, SERVER_DOMAIN_SSL
|
|
|
from Model.models import FAQModel, HelpLink
|
|
|
+from Object.Enums.RedisKeyConstant import RedisKeyConstant
|
|
|
from Object.RedisObject import RedisObject
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
@@ -423,6 +424,15 @@ class HelpLinkView(View):
|
|
|
return response.json(444, {'message': 'device_type和lang参数不能为空'})
|
|
|
|
|
|
try:
|
|
|
+ redis = RedisObject()
|
|
|
+ cache_key = RedisKeyConstant.HELP_LINK_TYPE.value + f'{device_type}:{lang}'
|
|
|
+
|
|
|
+ # 先尝试从缓存获取
|
|
|
+ cached_data = redis.get_data(cache_key)
|
|
|
+ if cached_data:
|
|
|
+ cached_data = json.loads(cached_data)
|
|
|
+ return response.json(0, cached_data)
|
|
|
+
|
|
|
# 查询匹配的帮助链接
|
|
|
help_link = HelpLink.objects.filter(
|
|
|
device_type=device_type,
|
|
@@ -440,6 +450,13 @@ class HelpLinkView(View):
|
|
|
'description': help_link.description
|
|
|
}
|
|
|
|
|
|
+ # 设置缓存,过期时间30天
|
|
|
+ try:
|
|
|
+ redis.set_data(cache_key, json.dumps(data), RedisKeyConstant.EXPIRE_TIME_30_DAYS.value)
|
|
|
+ except Exception as e:
|
|
|
+ print(f"设置Redis缓存出错: {str(e)}")
|
|
|
+ # 缓存失败不影响主流程
|
|
|
+
|
|
|
return response.json(0, data)
|
|
|
|
|
|
except Exception as e:
|