【问题标题】:How to get cache stats from @ring.lru wrapping a staticmethod in python?如何从 @ring.lru 获取缓存统计信息,在 python 中包装静态方法?
【发布时间】:2019-09-29 13:27:00
【问题描述】:

我正在使用ring 来缓存静态方法的结果,如下所示:

    @ring.lru()
    @staticmethod
    def get_hostname_by_id(object_id):
        return Monkey.get_single_monkey_by_id(object_id).hostname

我想打印我收到的未命中、命中和查询的统计数据。类似于https://docs.python.org/3/library/functools.html#functools.lru_cachecache_info 方法的东西会很有用。

我可以在ring 的 LRU 实现内部看到正在更新的统计字典。但是,我看不到如何访问这些数据。

有什么想法吗?

我使用的是 Python 2.7。

【问题讨论】:

  • 环中的lru_cache provides the same method: cache_info
  • 当尝试通过print(Monkey.get_hostname_by_id.cache_info()) 访问它时,我收到了AttributeError: 'CacheUserInterface' object has no attribute 'cache_info' @MatsLindh

标签: python caching ring


【解决方案1】:

在@MatsLindh 的帮助下,我找到了它。 LRU 缓存通过.storage.backend 访问。所以就我而言,它是Monkey.get_hostname_by_id.storage.backend.cache_info()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-12
    • 2012-07-22
    • 1970-01-01
    • 2010-10-28
    • 1970-01-01
    • 2011-04-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多