有没有人知道如何使用谷歌的Volley库清除单个NetworkImageView中缓存的图像?
我在一个NetworkImageView中有一个头像图像,并希望在将其上传到服务器后显示新图像。目前,如果执行profileImg.setImageUrl("myUrl", mImageLoader);
,会显示缓存的图像。
有没有人知道如何使用谷歌的Volley库清除单个NetworkImageView中缓存的图像?
我在一个NetworkImageView中有一个头像图像,并希望在将其上传到服务器后显示新图像。目前,如果执行profileImg.setImageUrl("myUrl", mImageLoader);
,会显示缓存的图像。
请看这个:
1)关闭缓存: 如果你想禁用某个URL的缓存,你可以使用以下setShouldCache()方法。
StringRequest stringReq = new StringRequest(....);
stringReq.setShouldCache(false);
2) 删除特定URL的缓存: 使用remove()删除URL的缓存。
yourRequestQueue.getCache().remove(url);
3) 清除所有缓存:
yourRequestQueue.getCache().clear(url);
另外,看看这个链接在这里。
希望这可以帮到你。
很抱歉,我来晚了。为确保我始终获取最新的头像图像,我采用了不同的方法,这种方法非常简单。
而不是尝试清除缓存中的个别图像,我使用以下方法。
int time = (int) (System.currentTimeMillis());//gets the current time in milliseconds
String myUrl = "www.mySite.com?timestamp=" + String.ValueOf(time);
profileImg.setImageUrl("myUrl", mImageLoader);
@Override
public void putBitmap(String url, Bitmap bitmap) {
// put(url, bitmap);
}
RequestQueue requests = Volley.newRequestQueue( context );
BitmapCache cache = new BitmapCache(cacheSize);
ImageLoader loader = new ImageLoader( requests, cache );
您可以这样清除所有内容:
public void clear () {
cache.evictAll();
requests.getCache().clear();
}
VolleySingleton.getInstance().getRequestQueue().getCache().clear();
3) VolleySingleton.getInstance().getRequestQueue().getCache().invalidate(ImageUrl,true);
我已经尝试了所有方法,但缓存仍未被删除。
To turn off the cache:
1
request.setShouldCache(false);
to remove the cache for a specific request:
1
queue.getCache().remove(url);
to clear all cache:
1
queue.getCache().clear();
to invalidate the cache: this will allow to display the cached data until the response is received. When the response is received, it will automatically override the cached data.
1
queue.getCache().invalidate(url, true);
for more details you can refer to the
url:http://androidresearch.wordpress.com/2014/02/01/android-volley-tutorial/