【发布时间】:2022-11-25 20:54:31
【问题描述】:
如果出现错误或变量为空,我试图删除特定路径上的烧瓶缓存,但我不知道该怎么做。
我发现了这个,但我认为这对我的情况没有帮助:
Delete specific cache in Flask-Cache or Flask-Caching
这是我的代码:
@nsaudio.route('/repeat/<string:text>/<string:chatid>/<string:voice>')
class AudioRepeatClass(Resource):
@cache.cached(timeout=120, query_string=True)
def get (self, text: str, chatid: str, voice: str):
try:
tts_out = utils.get_tts(text, voice=voice, timeout=120)
if tts_out is not None:
return send_file(tts_out, attachment_filename='audio.wav', mimetype='audio/x-wav')
else:
resp = make_response("TTS Generation Error!", 500)
return resp
except Exception as e:
return make_response(str(e), 500)
当 tts_out 为 None 并且出现异常时,我需要清除缓存
如果先例请求错误,我需要客户端调用 utils.get_tts 方法
怎么做?
【问题讨论】:
标签: python flask flask-caching