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

标签 java caching guava

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/

相关文章:

java - 为什么在比较两个 boolean 值时 & 在 java 中使用 &&?

java - 如果 try block 内有不必要的代码,性能会受到影响吗?

java - 如何使用 lambdaj 或其他工具过滤表

java - Guava Join 第三个参数 NULL

sql - 是否可以在单个查询中同时使用 order by 和 where

linux - 使用 dmsetup Kernel 3.9.6 创建 dm-cache

php - 在 Docker 环境中运行 Symfony 时的文件夹权限

java - 使用 Process p=runtime.getRuntime().exec ("java classname &lt;input_file") 执行 java 文件;

java - 每个字母出现的次数

java - 根据条件定期或仅运行一次 ScheduledExecutorService