需要使beaker_cache装饰器为特定控制器操作创建的缓存无效:
from pylons.decorators.cache import beaker_cache
class SampleController(BaseController):
@beaker_cache()
def home(self):
c.data = expensive_call()
return render('/home.myt')
def __clear_home_cache(self):
pass我可以在__clear_home_cache函数中使用region_invalidate()吗?
发布于 2011-03-16 05:47:49
了解如何使beaker_cache装饰器缓存的内容无效的一种方法是查看它是如何工作的以及它做了什么。它在GitHub上的pylons.decorators.cache模块here's the corresponding source file中定义。
基本上,您正在寻找为给定的控制器操作选择名称空间和缓存键的逻辑。这是由该文件中的create_cache_key()函数完成的。顺便说一句,该函数有一个有用的注释:
Example:
from pylons import cache
from pylons.decorators.cache import create_cache_key
namespace, key = create_cache_key(MyController.some_method)
cache.get_cache(namespace).remove(key)https://stackoverflow.com/questions/5185042
复制相似问题