Picasso Image Search Order: Cache → Disk Cache → Network
So, there are several scenarios that we need for Picasso's cache invalidation:
1. Invalid memory cache:
- Usercase: when the image is already being updated in the disk cache or remote host
Solution: flush url, file, uri cache if exists
mPicasso.with(appContext).invalidate(File); mPicasso.with(appContext).invalidate(Url); mPicasso.with(appContext).invalidate(Uri);
.
2. Make sure the memory cache and disk cache .
※ note: Online means updating directly in ImageView
User case: image updated on the remote host
Solution: Interrupting the image in the cache and disk cache then requests the image on the remote host
mPicasso.with(appContext) .load(url) .memoryPolicy(MemoryPolicy.NO_CACHE ) .networkPolicy(NetworkPolicy.NO_CACHE) .into(imageView);
-> Discard cache memory and disk cache
.
3. Make sure the cache cache and offline disk cache
※ note: Offline means the update does not upgrade to ImageView, just extracting the background for later use
※ Note. Using fetch () is good, but it also consumes a network resource, so please consider carefully, check scenario 4 below for a better solution
4. Make sure the cache cache and disk cache is offline, if there is a disk cache
- User case: only invalid cache if it already exists in disk cache
Decision. You should check the drive using the parameter: NetworkPolicy.OFFLINE cache before ejecting
mPicasso.with(appContext) .load(url) .memoryPolicy(MemoryPolicy.NO_CACHE) .networkPolicy(NetworkPolicy.OFFLINE) .fetch(new Callback() { @Override public void onSuccess() {
Picasso is an amazing library, I hope the square will add more convenience to the cache management API in the future.
NguyenDat Oct 12 '16 at 8:51 2016-10-12 08:51
source share