func中有大量sql查询、采集服务时,会严重超时如
延时3秒返回相加的结果

1
2
3
4
5
6
7
import time

def add(a,b):
time.sleep(2)
return a+b

print(add(1,2))

能不能加速呢,类似functools.lru_cache()、Flask-Cache
其实只要定义一个装饰器对参数与结果进行文件缓存、sql缓存就可加速

1
2
3
4
5
6
7
8
import time

@cache()
def add(a,b):
time.sleep(2)
return a+b

print(add(1,2))

ps:直接上redis不香么