Picasso by default doesn't resize images. If you do a simple call like the next one...
Picasso.with(context).load("https://goo.gl/v9EkbF").into(imageView);
...Picasso is caching the full-size image. From that moment, every time you call the same URL, Picasso will reuse that full-size image and let the GPU do the resizing into the view.
Use the resize() method you are only caching the resized image, and Picasso will need to download the image again if you use a different size.
Don't use the resize() option and you'll get better bandwidth usage, but be careful with memory usage.
The defaults in Picasso
Picasso does have automatic memory and disk caching. Any image that was requested recently will be in memory cache. If it isn't there Picasso will check the disk cache. If it's not available on disk, only then Picasso will start the network request.
All requested images are stored in both caches until they have to be deleted in order to free space.
The default's in 2.5.2 are:
- LRU memory cache of 15% the available application RAM
- Disk cache of 2% storage space up to 50MB but no less than 5MB.
- Picasso will use OkHttp as the Http client if it's included as a Gradle dependency. Otherwise Picasso will fall back to HttpUrlConnection.
You can increase the disk cache like this (example for 100MB):
Picasso picasso = new Picasso
.Builder(this)
.downloader(new OkHttpDownloader(getCacheDir(), 100000000))
.build();
Picasso.setSingletonInstance(picasso);
Changing the disc cache size does not change the cache policy.
Memory Policies
- MemoryPolicy.NO_CACHE: The image won't be served from memory. This one doesn't avoid to serve images from disk. To avoid disk look down on Network Policies.
- MemoryPolicy.NO_STORE: The image won't be stored in memory. Use this for images that will be loaded only once.
Example
Picasso
.with(context)
.load(https://goo.gl/v9EkbF)
.memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)
.into(imageView);
Network Policies
- NetworkPolicy.NO_CACHE: The image won't be served from disk cache.
- NetworkPolicy.OFFLINE: The image will (if possible) be served just from cache (memory or disk) but never from network.
Example:
Picasso
.with(context)
.load(https://goo.gl/v9EkbF)
.networkPolicy(NetworkPolicy.NO_CACHE)
.into(imageView);
Memory and caching considerations
- Glide uses by default RGB565 and cache a image resized into the
memory.
- Picasso uses by default RGB888 and cache the full size image into the
memory and let GPU does the real-time resizing when drawn.
RGB565 is half the size of RGB888. The result of using RGB565 and smaller images is that Picasso memory footprint is higher (might be 3x/4x) than Glide's.
Those are just the defaults. Glide can be configured to use RGB888 and Picasso to use RGB565. Picasso can be configured to throw into memory just the resized images like Glide.
Under the same setups, the memory footprint is almost the same.
Bandwidth considerations
- Glide caches separate file for each size. If you load another size of
the same image, it will be downloaded again before, resized and then
cached.
- Picasso takes always the full-size image from cache and then let the GPU make the resizing into the view.
You can ask Glide to cache everything, full-size image and resized images but by default Glide's bandwidth consumption is higher.
Note
Picasso 2.6 is coming and I have no idea about what's different/new.
Sources