刷新通用图像加载器缓存

时间:2015-04-14 17:59:17

标签: java android universal-image-loader

我使用一个凌空单身来装载图像

 private VolleySingleton(){
        mRequestQueue = Volley.newRequestQueue(VolleyApplication.getAppContext());

        mImageLoader = new ImageLoader(this.mRequestQueue, new ImageLoader.ImageCache() {
            private final LruCache<String, Bitmap> mCache = new LruCache<String, Bitmap>(10);
            public void putBitmap(String url, Bitmap bitmap) {
                mCache.put(url, bitmap);
            }
            public Bitmap getBitmap(String url) {
                return mCache.get(url);
            }
        });
    }

我需要刷新缓存以在更改照片时更新imageView。

我在这里读过MemoryCacheUtils,但似乎无法在我的代码中实现它,我可以在代码中使用MemoryCacheUtils吗?如果没有办法在我的imageLoader中刷新缓存?

修改

公开LruCache

  private VolleySingleton(){
        mRequestQueue = Volley.newRequestQueue(VolleyApplication.getAppContext());

        mImageLoader = new ImageLoader(this.mRequestQueue, new ImageLoader.ImageCache() {
            private final LruCache<String, Bitmap> mCache = new LruCache<String, Bitmap>(10);
            public void flushLruCache(){ mCache.evictAll();};
            public void putBitmap(String url, Bitmap bitmap) {
                mCache.put(url, bitmap);
            }
            public Bitmap getBitmap(String url) {
                return mCache.get(url);
            }
        });
    }

我尝试使用ImageLoader.ImageCache flush =(ImageLoader.ImageCache)mImageLoader;

我无法访问它。

1 个答案:

答案 0 :(得分:1)

LruCache使用方法evictAll(),您可以在ImageLoader子类中公开此方法以清除缓存。