为了进行测试,我想查看 LRU 缓存当前使用了多少 kB/MB。我将总大小设置为 4096。
有没有这样的函数:
public LruCache<String, Bitmap> myCache;
...
...
println(myCache.getUsedAmount());
或
println(myCache.getAvailabeSpace());
最佳答案
看看Documentation .
如果您不覆盖 sizeOf(K,V),则使用 size() 应该可以正常工作:
For caches that do not override sizeOf(K, V), this returns the number of entries in the cache. For all other caches, this returns the sum of the sizes of the entries in this cache.
您还可以浏览所有条目并检查它们的大小。
关于java - 获取Android LRUCache当前使用的内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31646922/