如何使烧杯缓存失效?
我有一个用烧杯缓存装饰器装饰的函数。该函数位于一个模块中,从该模块导入到主应用程序中。
from caching import cache, my_cached_function
现在,在一个函数中我使用了修饰函数:
def index():
data = my_cached_function() # no args
在另一个函数中,我尝试使缓存无效:
def new_item():
cache.invalidate(my_cached_function, 'namespace')
由于 Beaker 缓存配置为 'cache.type': 'memory'
,我也尝试过:
def new_item():
cache.invalidate(my_cached_function, 'namespace', type='memory')
我在这里做错了什么?
注释
在典型场景中,我大部分时间都会调用index()。我需要在调用 new_item() 时清除缓存,以便 index() 调用将考虑 new_item() 函数创建的新项目。
所讨论的应用程序是一个在 Bottle 框架之上运行的 Web 应用程序。
I have a function which is decorated with beaker cache decorator. The function is located in a module from which it is imported into the main app.
from caching import cache, my_cached_function
Now, in one function I used the decorated function:
def index():
data = my_cached_function() # no args
In another function, I try to invalidate the cache:
def new_item():
cache.invalidate(my_cached_function, 'namespace')
Since Beaker cache is configured with 'cache.type': 'memory'
, I've also tried:
def new_item():
cache.invalidate(my_cached_function, 'namespace', type='memory')
What am I doing wrong here?
NOTES
In a typical scenario, I would call index() most of the time. I need the cache to be cleared whenever new_item() is called, so that the index() call will take into account the new items created by new_item() function.
The application in question is a web application running on top of bottle framework.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在调用
my_cached_function
之前使缓存失效。有关示例,请参阅 beaker.cache.CacheManager 文档 。You need to invalidate the cache before
my_cached_function
is called. See the beaker.cache.CacheManager documentation for an example.