pythoncachingbeaker

Beaker: how access a cache created by decorator programmatically?


I have a cached method like this:

from beaker.cache import CacheManager
from beaker.util import parse_cache_config_options

cache = CacheManager(**parse_cache_config_options({'cache.type': 'memory'}))

@cache.cache('test',expire=100000)
def f(x,y,z=True):
    ....

I need to use this cache programmatically from another method to invalidate some (not all) cached values explicitly. How can I do this?


Solution

  • @cache.cache('test', expire=10000)
    def plus(x, y):
        return x + y
    
    plus(8, 9)
    plus(11, 12)
    
    # invalidate plus(11, 12)
    cache.invalidate(plus, 'test', 11, 12, expire=10000)