有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java获取LRUCache Android中使用的当前内存

为了进行测试,我想看看我的LRU缓存中当前使用了多少kB/MB。我把总尺寸设为4096

是否有类似以下功能:

public LruCache<String, Bitmap> myCache;
...
...
println(myCache.getUsedAmount());

println(myCache.getAvailabeSpace());

共 (1) 个答案

  1. # 1 楼答案

    看一下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.

    您还可以浏览所有条目并检查其大小