Clear cache of UIL library - android

I am using universal image loader library for loading the images in my listview. I want to clear the cache for all the images at once.
I know how to do it for one image at a time.
MemoryCacheUtils.removeFromCache("file://"+path, ImageLoader.getInstance().getMemoryCache());
DiskCacheUtils.removeFromCache("file://"+path, ImageLoader.getInstance().getDiskCache());
How can I do this?

You can do that by:
imageLoader.clearMemoryCache();
or
imageLoader.getDiskCache().clear();
it depends on your configuration.

You can clear the memory cache and the disk cache distinctly. For each just call:
ImageLoader.getInstance().clearMemoryCache();
ImageLoader.getInstance().clearDiskCache();
It will erase all stored cache data.

Related

glide take time to load image even if image load from cache?

I have RecyclerView where image load from server URL. so I use Glide library to load an image, glide store image into cache to reload as fast as possible.
I use a placeholder() as a loader for loading image first time, but if I off the internet and start app its still load placeholder first and then load an image into ImageView.
So, my question is, is there any way to load an image into ImageView so user experience like smoothness (offline) app while loading images
Glide.with(context)
.load(www.abc.com/abcd.jpg)
.placeholder(R.drawable.placeholder)
.into(viewHolder.ivSleepImage)
you can check this app Walking UP it loads image first time than there is no loader, and next time when image load means when you open app image already loaded in list.
Please somebody help me to achieve this task
There are 2 ways you can do that task but it can be very lengthy because storing and loading is not the way to approach in the android development
1.Store the data in the cache
2.store data in the database
the cache strategy is relatively easy. as you are requesting the data from the server if the connection is not available then you have to load data from the cache. Same can be said from the database but it is very lengthy and can be very slow.
A quick solution to your problem would be to add diskCacheStrategy to your Glide call. This would help you cache ALL versions of your image and thus reduce load-time. Here's an implementation:
Glide.with(context)
.load(www.abc.com/abcd.jpg)
.placeholder(R.drawable.placeholder)
.into(viewHolder.ivSleepImage)
.diskCacheStrategy(DiskCacheStrategy.ALL)
I hope this helps. Merry coding!

How to invalidate Glide cache for some specific images

I'm writing an app which needs to load a lot of images from the internet (a manga reader). I need to cache some thumbnail images for offline use, any others should be cleared when app closed.
I read some about cache invalidation on Glide page, they said the best way is to change the content url, but how Glide know if it is a modified url of old content or a new one? I'm new to Glide here.
https://github.com/bumptech/glide/wiki/Caching-and-Cache-Invalidation
Thank in advance :)
You can use following to load image:
Glide.with(context)
.signature(new StringSignature(yourVersionMetadata))
.into(imageView)
Just change yourVersionMetadata when you load image and it will not load from cache if yourVersionMetadata is different.

Android Image invalidate in fresco

I am migrating android image caching library from picasso to fresco. I want to know if there is any way to invalidate image already catched as I am adding feature to replace existing image there is way to do so in picasso like
Picasso.with(context).invalidate(URI);
This line remove the cached image and use new one using the url provided which is same like,
http://example.com/image_path
In fresco I have tried using
Fresco.getImagePipeline().evictFromMemoryCache(uri);
This is removing image from view but adding same old cached image again and not getting new one from network as it is working in picasso.
Please refer question Invalidate cache in Picasso The accepted answer doing great in case of picasso.
Fresco.getImagePipeline().evictFromMemoryCache(uri);
Above code line remove the image from the catche but image remains there in the disk and render same if called. We need to remove same image from disk as well. Bellow two lines remove the the image from disc cache also we need to remove the small that is thumbnail image if saved from disk cache.
Fresco.getImagePipelineFactory().getMainDiskStorageCache().remove(new SimpleCacheKey(uri.toString()));
Fresco.getImagePipelineFactory().getSmallImageDiskStorageCache().remove(new SimpleCacheKey(uri.toString()));
Note: if you are using custom cache key you need to change it that way.
Try this
public static void clearCache(){
//
ImagePipeline imagePipeline = com.facebook.drawee.backends.pipeline.Fresco.getImagePipeline();
imagePipeline.clearMemoryCaches();
imagePipeline.clearDiskCaches();
// combines above two lines
imagePipeline.clearCaches();
}

Android Picasso remove entry from cache

Does anyone know of a way to remove entries from Picasso default Cache / invalidate?
I went over their api (Also Picasso Cache class ) and couldn't find any way of doing it. I'm not interested in skipMemoryCache because most of the time the image Should be loaded from the cache.
Thanks!
Roy
Now it's possible to invalidate cache using Picasso.invalidate().
Usage examples:
Picasso.with(context).invalidate(uri);
Picasso.with(context).invalidate(pathString);
Picasso.with(context).invalidate(file);

Universal Image Loader - removing single image from cache not working

I calling following code before loading an image:
String url = getUrlImageIcon();
MemoryCacheUtil.removeFromCache(url, ImageLoader.getInstance().getMemoryCache());
DiscCacheUtil.removeFromCache(url, ImageLoader.getInstance().getDiscCache());
ImageLoader.getInstance().displayImage(url, imageView, listener);
My Problem is, this is not deleting the image from cache, the image loader is still displaying the old image afterwards... The old image is not even existing on the server anymore...
How can I remove all cached files from an image correctly?
PS: I'm using the up-to-date version 1.9.1...
What #vanomart answered is perfect, just to update the answer. Currently, UIL supports,
MemoryCacheUtils.removeFromCache(imageUri, imageLoader.getMemoryCache());
DiskCacheUtils.removeFromCache(imageUri, imageLoader.getDiskCache());
So, there is better way to clear disk cache.
According to developer of this library is solution quite simple. All you need to do is to delete cached image from memory and also from disk. How to do that is shown below.
File imageFile = imageLoader.getDiscCache().get(imageUri);
if (imageFile.exists()) {
imageFile.delete();
}
MemoryCacheUtils.removeFromCache(imageUri, imageLoader.getMemoryCache());
Snippet above is from this issue.

Categories

Resources