I am using the Glide to display images in my app. Now I want to know the location where the Glide is storing the cached images downloaded from the urls.
I am using below code to display image.
Glide.with(mContext)
.load(mData.get(position).getImage())
.centerCrop()
.override(300, 300)
.placeholder(R.drawable.default_small)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.into(holder.ivCapturedImage);
Glide will put all image resources into the memory cache by default.
By default, Glide uses memory and disk caching to avoid unnecessary network calls, it checks into multiple layers of caches before initiating a new request call for an image.
A disk cache can be used in these cases to persist processed bitmaps and help decrease loading times where images are no longer available in a memory cache. Of course, fetching images from disk is slower than loading from memory and should be done in a background thread, as disk read times can be unpredictable.
This is one available method if you are using Glide 4.8.0 or higher
Kotlin:
val file: File = Glide.with(activity).asFile().load(url).submit().get()
val path: String = file.path
Java:
File file = Glide.with(activity).asFile().load(url).submit().get();
String path = file.getPath();
Then you can get a path looks like
/data/user/0/{package_name}/cache/image_manager_disk_cache/64c0af382f0a4b41c5dd210a3e945283d91c93b1938ee546f00b9ded701a7e40.0
private String getImgCachePath(String url) {
FutureTarget<File> futureTarget = Glide.with(getBaseContext()).load(url).downloadOnly(100, 100);
try {
File file = futureTarget.get();
String path = file.getAbsolutePath();
return path;
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
return null;
}
the parameter url is network address of the picture,the 100,100 is the width and height of the cached picture ,you can change them according to your needs. Then,The path is the cache path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With