Glide Version: 3.7.0
Integration libraries: 3.4.1
Device/Android Version:Redmi 3s Prime/6.0.1
Issue details / Repro steps / Use case background:
I am using glide code to load images and it will run properly but there is issue of cache memory increasings due to loading lots of images. my expectation is to clear only those "cache memory which is two days old" in my application.Please provide me right way to resolve this issue.
Glide load line / GlideModule (if any) / list Adapter code (if any):
Glide.with(holder.imagePhoto.getContext())
.load(post.content)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
holder.progress_view_post.setVisibility(View.GONE);
holder.square_frame_layout.setVisibility(View.GONE);
return false;
}
})
.into(holder.imagePhoto);.
Layout XML:
<FrameLayout xmlns:android="...
Stack trace / LogCat:
paste stack trace and/or log here
I think by memory, you mean size on the sdcard?
If so, Glide uses an LRU disk cache by default with a fixed size. You can see options for changing the default size or implementation here for v3: https://github.com/bumptech/glide/wiki/Configuration#disk-cache
Sorry for my poor English language. My issue is regarding application specific cache memory.I use default Glide cache mechanism to load images.we try to make social application like Instagram where user will post and view images.When number of post is visiting by user is increase according default glide cache mechanism device generate application cache.so here we want to delete two days old cache automatically.
Thanks for clarifying. I think the documentation I pointed you to is correct. You can use a GlideModule to set your own implementation of the DiskCache with whatever functionality you need.
You can also just call clearDiskCache() in your own code if you want to write the two day limit outside of a DiskCache implementation, see: http://bumptech.github.io/glide/javadocs/380/com/bumptech/glide/Glide.html#clearDiskCache()
We implemented following things to limit Cache size and its working fine but did not find any parameter to set number of days(So I can keep only two days cache and other days cache will be removed).
public class GlideConfiguration implements GlideModule {
private static final int PHOTOS_CACHE_SIZE = 5; // Mbytes
@Override
public void applyOptions(Context context, GlideBuilder builder) {
builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
builder.setDiskCache(new DiskLruCacheFactory(Glide.getPhotoCacheDir(context).getAbsolutePath(), PHOTOS_CACHE_SIZE * 1024 * 1024));
}
@Override
public void registerComponents(Context context, Glide glide) {
OkHttpClient okHttpClient = Network.getOkHttpClient()
.newBuilder()
.addInterceptor(new LoggingInterceptor(false))
.build();
glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(okHttpClient));
}
}
Yes, Glide by default is LRU, we don't support time based evictions and don't currently plan to.
You can implement the DiskCache interface yourself to add a time based requirement.
You can also implement the time requirement outside of Glide and just clear the entire cache every two days with clearDiskCache().
OK thanks.Is there any method to retrieve gradle cache creation date and time.so it easy to implement DiskCache inteface for me.
I'm not sure what you mean by gradle cache creation date?
Glide doesn't store any data about time, but you could use File#lastModified in your DiskCache implementation to check when an entry was created if that's what you're asking?
Thanks.Yes we want file last modified date.
This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.
Whats happen if cache is full ? Glide cover this automatic ? Erase old and start caching again ?
Whats happen if cache is full ? Glide cover this automatic ? Erase old and start caching again ?
Please Answer this
targetSdkVersion 29 ❎
targetSdkVersion <29 ✅
Most helpful comment
Whats happen if cache is full ? Glide cover this automatic ? Erase old and start caching again ?