如何使 Pylons 中的 beaker_cache 失效?

发布于 2024-10-20 01:56:43 字数 405 浏览 8 评论 0原文

需要使由 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷情妓 2024-10-27 01:56:43

了解如何使 beaker_cache 装饰器缓存的内容无效的一种方法是查看它的工作原理和用途。它在 pylons.decorators.cache 模块中定义,这是 GitHub 上相应的源文件

基本上,您正在寻找为给定控制器操作选择命名空间缓存键的逻辑。这是通过 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)

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 in pylons.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:

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文