Android Picasso Configure LruCache Size

不问归期 提交于 2019-11-28 18:00:00
Jake Wharton

By default, Picasso uses 1/7th of the available heap for it's LRU. This is a "happy" fraction that works best on all devices well enough.

You can configure the size of the memory cache by passing a custom instance to Picasso.Builder. It can be an instance of the LruCache which takes a max size or any other instance of Cache.

Picasso p = new Picasso.Builder(context)
    .memoryCache(new LruCache(24000))
    .build();

Before you go shrinking this cache size, however, remember that keeping Bitmap instances in RAM allows them to be instantly displayed. Unused RAM is wasted RAM. The memory cache should use as much RAM as possible without causing OOMs (obviously) or unnecessary GC to free space.

Below Code Will Increase Picasso Cache Size To 250 MB.

Picasso picasso =  new Picasso.Builder(this).downloader(new OkHttpDownloader(getCacheDir(), 250000000)).build();
Picasso.setSingletonInstance(picasso);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!