开发者

How to make invalidating Beaker cache work?

开发者 https://www.devze.com 2023-02-06 22:50 出处:网络
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.

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 bottl开发者_Go百科e framework.


You need to invalidate the cache before my_cached_function is called. See the beaker.cache.CacheManager documentation for an example.

0

精彩评论

暂无评论...
验证码 换一张
取 消