【发布时间】: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_cache 的cache_info 方法的东西会很有用。
我可以在ring 的 LRU 实现内部看到正在更新的统计字典。但是,我看不到如何访问这些数据。
有什么想法吗?
我使用的是 Python 2.7。
【问题讨论】:
-
环中的
lru_cacheprovides the same method:cache_info。 -
当尝试通过
print(Monkey.get_hostname_by_id.cache_info())访问它时,我收到了AttributeError: 'CacheUserInterface' object has no attribute 'cache_info'@MatsLindh