Android Lrucache类注意事项

使用例子:

int cacheSize = 4 * 1024 * 1024; // 4MiB
LruCache bitmapCache = new LruCache(cacheSize) {
    protected int sizeOf(String key, Bitmap value) {
        return value.getByteCount();
    }

注意: 默认sizeOf()返回值是1,使用时应重写该方法。如果未重写sizeOf方法,cacheSize表示的是最大缓存多少项Item.

 
     
/**
 * Returns the size of the entry for {@code key} and {@code value} in
 * user-defined units.  The default implementation returns 1 so that size
 * is the number of entries and max size is the maximum number of entries.
 *
 * 

An entry's size must not change while it is in the cache. */ protected int sizeOf(K key, V value) { return 1; }



你可能感兴趣的:(Android,算法,Lrucache,LRU)