关于Aestate查不出数据
排查
- sql写对了没
- 逻辑有没有问题
其他情况
这种情况就是需要我们解决的了
aestate有一个缓存机制,他会阻断执行sql并且将缓存中的数据返回到我们的结果集对象QuerySet。如果这时候你需要实时数据,那么就会造成数据的不准确,这个时候我们就需要做一件事情让aestate的缓存不管理我们的sql
解决方案
from aestate.work.Cache import SqlCacheManage, CacheStatus
# 关闭缓存
SqlCacheManage.status = CacheStatus.CLOSE
在你的程序不需要使用缓存的位置设置将缓存关闭,在结束之后开启缓存即可
示例
例如我的这段websocket
from aestate.work.Cache import SqlCacheManage, CacheStatus
@accept_websocket
def statisticSecond(request):
"""
商家端概览统计,秒
:param request:
:return:
"""
if request.is_websocket():
if request.is_websocket():
while True:
merchant_info = aj.load(request.session[Cookie.Merchant.INFO.value])
# 查询之前关闭缓存
SqlCacheManage.status = CacheStatus.CLOSE
mb = MerchantMapper().findstatistic(_type='second', merchant_id=merchant_info['id'])
# 查询完了之后开启缓存
SqlCacheManage.status = CacheStatus.OPEN
result = {}
try:
result['second'] = mb[0]
except:
pass
request.websocket.send(aj.dumps(result))
time.sleep(1)
else:
return Result.success(data='连接已断开')