自动删除键时的Flask-Caching回调事件 [英] Flask-Caching call back event when key delete automatically

查看:77
本文介绍了自动删除键时的Flask-Caching回调事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java应用程序和flask应用程序,该Java应用程序会将一些值发送到flask应用程序,需要将其保存在缓存中,因此我正在使用flask缓存,并且我在flask缓存中有一些默认超时.问题是,一旦根据超时从烧瓶缓存中自动删除了密钥,我就需要将该值发送到已删除密钥的java应用程序.我不确定如何知道从缓存中自动删除一个值,我们是否在烧瓶缓存中回调了一个方法,该方法将通知该值已删除烧瓶缓存,或者建议我可以使用哪种缓存来解决此问题?问题.

I have one java app and flask app the java app will send some value to the flask app that I need to save it in the cache so I am using flask-caching and I am having some default time out in the flask caching. The problem is once a key is deleted from the flask caching automatically based on the timeout I need to send the value to the java app which key is deleted. I am not sure how I how can know that a value is deleted automatically from cache do we have some call back a method in flask caching that will notify that value is deleted flask caching or suggest me what kind of caching I can use to solve this problem.

谢谢.

推荐答案

如果您使用Redis Cache作为后端.您可以使用Redis通知.

If you are using Redis Cache as the backend. You can use Redis notifications.

基本上这是两个步骤.

  1. 使用Flask Cache和Redis作为后端来设置密钥.
  2. 通过pub sub订阅Java应用程序中的Redis通知.

您也可以使用键前缀等.以便在Java应用程序中标识密钥到期的通知.

You could use a key prefix etc as well. So as to identify the notification of the key expiry in the Java app.

有关实现的详细信息,此答案 redis python中的密钥到期通知将进一步为您提供帮助.

For implementation details, this answer Notification of key expiration in redis python will further help you.

这篇关于自动删除键时的Flask-Caching回调事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆