简体   繁体   English

自动删除键时的Flask-Caching回调事件

[英]Flask-Caching call back event when key delete automatically

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. 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.问题是一旦从 flask 缓存中删除密钥后,我需要根据超时自动将值发送到 java 应用程序,该密钥被删除。 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.我不知道我怎么知道一个值是从缓存中自动删除的,我们是否有一些回调 flask 缓存中的方法会通知该值已删除 flask 缓存或建议我可以使用哪种缓存来解决这个问题问题。

Thanks in advance.提前致谢。

If you are using Redis Cache as the backend.如果您使用 Redis 缓存作为后端。 You can use Redis notifications.您可以使用 Redis 通知。

Basically the 2 steps would be.基本上这两个步骤是。

  1. SET the key using Flask Cache with Redis as a backend.使用 Flask 缓存和 Redis 作为后端设置密钥。
  2. Subscribe via pub sub to Redis notifications from the Java App.通过 pub sub 订阅来自 Java 应用程序的 Redis 通知。

You could use a key prefix etc as well.您也可以使用键前缀等。 So as to identify the notification of the key expiry in the Java app.以便在Java app中识别密钥到期的通知。

For implementation details, this answer Notification of key expiration in redis python will further help you.有关实现细节,这个答案redis python 中的密钥过期通知将进一步帮助您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM