Skip to content

Instantly share code, notes, and snippets.

@kojiokb
Created August 18, 2012 13:49
Show Gist options
  • Save kojiokb/3386953 to your computer and use it in GitHub Desktop.
Save kojiokb/3386953 to your computer and use it in GitHub Desktop.
LruCacheの使い方
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;
public final class ImageCache {
private static final int MEM_CACHE_SIZE = 1 * 1024 * 1024; // 1MB
private static LruCache<String, Bitmap> sLruCache;
static {
sLruCache = new LruCache<String, Bitmap>(MEM_CACHE_SIZE) {
@Override
protected int sizeOf(String key, Bitmap bitmap) {
return bitmap.getRowBytes() * bitmap.getHeight();
}
};
}
private ImageCache() {
}
public static void setImage(String key, Bitmap bitmap) {
if (getImage(key) == null) {
sLruCache.put(key, bitmap);
}
}
public static Bitmap getImage(String key) {
return sLruCache.get(key);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment