无论如何要说番石榴缓存是在禁用统计信息的情况下构建的?
Is there anyway to tell that a Guava Cache was constructed with stats disabled?
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.
来自 [CacheBuilder.recordStats()
][2] 的 JavaDocs,已强调。
据我所知,无法区分从未调用过的缓存和未调用 recordStats()
构建的缓存以启用统计信息的累积。 Cache
接口本身似乎没有暴露任何迹象。我错了吗?
如果没有记录这样的方法或标志,为什么不呢? 10 次中有 9 次,很明显您的缓存实际上正在被调用,但我今天浪费了一个小时试图弄清楚为什么我的缓存没有记录统计信息...
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.
recordStats
public CacheBuilder<K,V> recordStats()
Enable the accumulation ofCacheStats
during the operation of the cache. Without thisCache.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.
来自 [CacheBuilder.recordStats()
][2] 的 JavaDocs,已强调。
据我所知,无法区分从未调用过的缓存和未调用 recordStats()
构建的缓存以启用统计信息的累积。 Cache
接口本身似乎没有暴露任何迹象。我错了吗?
如果没有记录这样的方法或标志,为什么不呢? 10 次中有 9 次,很明显您的缓存实际上正在被调用,但我今天浪费了一个小时试图弄清楚为什么我的缓存没有记录统计信息...
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.