I\'m loading images from URLs (http://) with Picasso.
Sometimes when i try to \"preload\" an image using Picasso\'s fetch() method, the image doesn\'t get cache
This example use OkHttp as http client for Picasso and setup max Disk cache size and also memory cache.
// Size in bytes (10 MB)
private static final long PICASSO_DISK_CACHE_SIZE = 1024 * 1024 * 10;
// Use OkHttp as downloader
Downloader downloader = new OkHttpDownloader(getApplicationContext(),
PICASSO_DISK_CACHE_SIZE);
// Create memory cache
Cache memoryCache = new LruCache(maxSize);
mPicasso = new Picasso.Builder(getApplicationContext())
.downloader(downloader).memoryCache(memoryCache).build();
You can do:
int maxSize = MAX_CACHE_SIZE;
Picasso picasso = new Picasso.Builder(context)
.memoryCache(new LruCache(maxSize))
.build();
Picasso uses a Cache interface type to manage the cache. They provide the default implementation, LruCache, which has a constructor that accepts the max size in bytes as an argument.
Seems like the other answer uses the wrong function. It should be memoryCache, not setCache.