Iva*_*oll 8 android android-volley
有人知道是否可以使用Googles Volley库从单个NetworkImageView清除缓存的图像?
我在NetworkImageView中有一个头像图像,并希望在我将其上传到服务器后显示新图像.目前,如果我这样做,
profileImg.setImageUrl("myUrl", mImageLoader);
我得到缓存的图像.
看一下这个 :
1)关闭缓存: 如果要禁用特定URL的缓存,可以使用如下的setShouldCache()方法.
StringRequest stringReq = new StringRequest(....);
stringReq.setShouldCache(false);
Run Code Online (Sandbox Code Playgroud)
2)删除特定URL的缓存:使用remove()删除URL的缓存.
yourRequestQueue.getCache().remove(url);
Run Code Online (Sandbox Code Playgroud)
3)删除所有缓存:
yourRequestQueue.getCache().clear(url);
Run Code Online (Sandbox Code Playgroud)
另外,请在此处查看此链接.
希望这可以帮助.
所以迟来地回答我自己的问题。我最终采取了不同的方法来确保我始终获得头像图像的最新副本,结果非常简单。
我没有尝试从缓存中清除单个图像,而是使用以下方法。
int time = (int) (System.currentTimeMillis());//gets the current time in milliseconds
String myUrl = "www.mySite.com?timestamp=" + String.ValueOf(time);
profileImg.setImageUrl("myUrl", mImageLoader);
Run Code Online (Sandbox Code Playgroud)
其作用是将一个虚构参数附加到我调用的 url 中,以获取具有当前时间戳的图像。这保证了我总是调用唯一的 url,因此我总是获得该图像的最新版本。
这种方法的优点在于它不仅限于 Volley,而且可以根据您选择的网络调用方式使用。
归档时间: |
|
查看次数: |
6737 次 |
最近记录: |