gpt4 book ai didi

java - 无论如何,有没有办法告诉我们 Guava Cache 是在禁用统计信息的情况下构建的?

转载 作者:行者123 更新时间:2023-11-30 03:18:46 27 4
gpt4 key购买 nike

recordStats
public CacheBuilder<K,V> recordStats()
Enable the accumulation of CacheStats during the operation of the cache. Without this Cache.stats() will return zero for all statistics. Note that recording stats requires bookkeeping to be performed with each operation, and thus imposes a performance penalty on cache operation.

来自 JavaDocs [ CacheBuilder.recordStats() ][2],添加了强调。

据我所知,没有办法区分从未被调用过的缓存和没有 recordStats() 构建的缓存。被调用以实现统计数据的积累。 Cache 接口(interface)本身似乎没有暴露任何指示。我错了吗?

如果没有记录这样的方法或标志,为什么不呢?十分之九,很明显您的缓存实际上正在被调用,但我今天浪费了一个小时试图找出为什么我的缓存没有记录统计信息...

最佳答案

No, and unfortunately there's not going to be.

kevinb9n commented 2015-07-30T18:17:42Z
I remember agonizing over whether to try to change the behavior to return -1s years ago, and unfortunately we already felt it was too late. It's also not feasible to add new interface methods at this point. We are sorry.

With interfaces no changes are ever backward-compatible; it must always break either a consumer or an implementor. In this case every concrete class implementing Cache outside Guava would break. After we're on Java 8, we can add interface methods by supplying a reasonable "default" implementation. But note that in this case the best we could do is probably throw new UnsupportedOperationException(); which isn't too exciting.

关于java - 无论如何,有没有办法告诉我们 Guava Cache 是在禁用统计信息的情况下构建的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31870286/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com