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
Programmatically Change Input Type of the Edittext from Password to Normal & Vice Versa
A Failure Occurred While Executing Com.Android.Build.Gradle.Internal.Tasks
How to Resolve "Waiting for Debugger" Message
Manifest Merger Failed Targeting Android 12
Overlap Scrolling View with Appbarlayout
Cannot Resolve Symbol 'Appcompatactivity'
Permission Denial: Startforeground Requires Android.Permission.Foreground_Service
Android: Remove All the Previous Activities from the Back Stack
Version Conflict Updating to 8.4.0
Android - R Cannot Be Resolved to a Variable
Run Code When Android App Is Closed/Sent to Background
Android:Get View Reference to a Menu Item
Progressdialog Not Shown When Asynctask.Get() Called
How to Set Up Dagger Dependency Injection from Scratch in Android Project