【问题标题】:Beaker: how access a cache created by decorator programmatically?烧杯:如何以编程方式访问装饰器创建的缓存?
【发布时间】:2014-01-23 21:29:20
【问题描述】:

我有一个这样的缓存方法:

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):
    ....

我需要通过另一种方法以编程方式使用此缓存来显式地使某些(不是全部)缓存值无效。我该怎么做?

【问题讨论】:

    标签: python caching beaker


    【解决方案1】:
    @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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-24
      • 1970-01-01
      • 2011-06-29
      相关资源
      最近更新 更多