如何使 Pylons 中的 beaker_cache 失效?
需要使由 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()
吗?
Need to invalidate a cache created by beaker_cache
decorator for a specific controller action:
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
Can I use region_invalidate()
inside __clear_home_cache function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
了解如何使
beaker_cache
装饰器缓存的内容无效的一种方法是查看它的工作原理和用途。它在 pylons.decorators.cache 模块中定义,这是 GitHub 上相应的源文件。基本上,您正在寻找为给定控制器操作选择命名空间和缓存键的逻辑。这是通过 create_cache_key() 函数完成的那个文件。顺便说一句,该函数有一个有用的注释:
One way to find out how to invalidate stuff cached by
beaker_cache
decorator is to look at how it works and what it does. It is defined inpylons.decorators.cache
module, here's the corresponding source file on GitHub.Basically you're looking for the logic that chooses namespace and cache key for a given controller action. This is done by create_cache_key() function in that file. And, incidentally, that function has a helpful comment: