Remove/Delete particular cache Glide

匿名 (未验证) 提交于 2019-12-03 01:09:02

问题:

There I am currently working on an user based apps like friends app it simply shows the list of users with thier avatar and caching images using this wonderful library but problem occurs when the url of a particular user's avatar changes and there are two different avatar images save in cache directory of app. there is no need of more than one avatar pic or single user. in long run it will full with these garbage caches of different user's pervious avatars the need is to only cache single avatar of user when url changes remove previous one cache and cache updated avatar

Glide Version: 4.7.1

there are two different cache files of a single user there is no need of previous one!

Please Guide this is serious hurdle..

Please Note that Urls of avatar are dynamic only identifier will be user phone_number

回答1:

You can try this way-

public class GlideIdWithModifiedTime extends GlideUrl {  private String mKey;  public GlideIdWithModifiedTime(String url,String id, String modifiedTime) {     super(url);     mKey = id + "_" +modifiedTime;     Log.d("GlideKey",mKey); }  @Override public String getCacheKey() {     return mKey; }  @Override public String toString() {     return super.getCacheKey(); } 

}

To use it -

 Glide.with(context)                 .load(new GlideIdWithModifiedTime("imageUrl","someId","modifiedTime")                 .apply(new RequestOptions().placeholder(R.drawable.placeholder))                 .into(holder.courseThumbnail); 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!