Remove Image from Cache in Glide Library

Remove image from cache in Glide library

This is how I solved this problem.

Method 1: When the URL changes whenever image changes

Glide.with(DemoActivity.this)
.load(Uri.parse("file://" + imagePath))
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.into(mImage);

diskCacheStrategy() can be used to handle the disk cache and you can skip the memory cache using skipMemoryCache() method.

Method 2: When URL doesn't change, however, image changes

If your URL remains constant then you need to use Signature for image cache.

Glide.with(yourFragment)
.load(yourFileDataModel)
.signature(new StringSignature(yourVersionMetadata))
.into(yourImageView);

Glide signature() offers you the capability to mix additional data with the cache key.

  • You can use MediaStoreSignature if you are fetching content from media store. MediaStoreSignature allows you to mix the date modified time, mime type, and orientation of a media store item into the cache key. These three attributes reliably catch edits and updates allowing you to cache media store thumbs.
  • You may StringSignature as well for content saved as Files to mix the file date modified time.

Clear Glide Image Cache in Android

clearMemory() must be called on the main thread.
clearDiskCache() must be called on a background thread.

You can't call both at once on the same thread.



Related Topics



Leave a reply



Submit