asedCache抛出FileNotFoundException

asedCache抛出FileNotFoundException

本文介绍了凌空DiskBasedCache抛出FileNotFoundException异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 BitmapLRUCache由罗宾逊的三分球的在我的Andr​​oid应用程序的图像缓存。这是LRU缓存排球的实现,因为它本身并不能提供任何的图像缓存。

虽然它并使用 DiskBasedCache 缓存HTTP请求。现在来这个问题,我得到FileNotFoundExceptions时反复DiskBasedCache试图获取或删除缓存条目。

下面的示例日志。

  23833凌空D [47291] DiskBasedCache.remove:无法删除缓存项key=http://a2.mzstatic.com/us/r30/Music1/v4/69/66/0b/69660b50-7771-a43a-919f-26d8b6ae37aa/UMG_cvrart_00602537957941_01_RGB72_1500x1500_14UMGIM31675.400x400-75.jpg,文件名= 1509125231-2004731303
 23833凌空D [47291] DiskBasedCache.get:/data/data/com.vibin.billy.debug/cache/volley/6408634861932551223:java.io.FileNotFoundException:/data/data/com.vibin.billy.debug/cache/凌空/ 6408634861932551223:打开失败:ENOENT(没有这样的文件或目录)
 23833凌空D [47291] DiskBasedCache.remove:无法删除缓存项key=http://a2.mzstatic.com/us/r30/Music4/v4/99/f7/ac/99f7ac13-0dd6-8841-96e0-2a1c18041d84/UMG_cvrart_00602537854097_01_RGB72_1800x1800_14UMGIM03851.400x400-75.jpg,文件名= 6408634861932551223

为什么DiskBasedCache处理,当我用初始化BitmapLRUcache(见下文)?

的ImageLoader的图像缓存

  ImageLoader的ImageLoader的=新ImageLoader的(Volley.newRequestQueue(本),新BitmapLruCache());

下面是code我使用缓存。

 包com.vibin.billy;进口android.graphics.Bitmap;
进口android.support.v4.util.LruCache;
进口android.util.Log;进口com.android.volley.toolbox.DiskBasedCache;
进口com.android.volley.toolbox.ImageLoader;/ **
 *基本LRU内存缓存。
 *
 * @author罗宾逊三分球
 * /
公共类BitmapLruCache
        扩展LruCache<弦乐,位图>
        实现ImageLoader.ImageCache {    私有静态最后弦乐TAG = BitmapLruCache.class.getSimpleName();    公共BitmapLruCache(){
        这个(getDefaultLruCacheSize());
    }    公共BitmapLruCache(INT sizeInKiloBytes){
        超(sizeInKiloBytes);
    }
    @覆盖
    保护INT整型尺寸(字符串键,位值){
        返回value.getRowBytes()* value.getHeight()/ 1024;
    }    @覆盖
    公共位图getBitmap(字符串URL){
        //Log.d(TAG,抢+网址);
        得到的回报(URL);
    }    @覆盖
    公共无效putBitmap(字符串URL,位图位图){
         //Log.d(TAG,放+网址);
         把(URL,位图);
    }    公共静态INT getDefaultLruCacheSize(){
        最终诠释maxMemory =
                (中间体)(调用Runtime.getRuntime()maxMemory()/ 1024);
        最终诠释的cachesize = maxMemory / 8;        Log.d(TAG的cachesize是+ CACHESIZE);        Log.d(TAG,CACHESIZE +是缓存大小);        返回CACHESIZE;
    }
}


解决方案

for image caching volley use 2 level cache mechanism, that means one level is in your RAM BitmapLRUcache and another one is on your Disk DiskBasedCache. why? because of reading and writing images from disk takes longer time than just simply reading and writing some Strings and gives poor performance. so at the first time when you request Volley to download your images Volley first looks at the cache level one, if your images are not there Volley looks at cache level 2 and if your images are not there Volley sends your download request to the server.

because your DiskBasedCache size is limited(by default is 5MB) and also it is LRU, which means if Volley wants to store an image on the DiskBasedCache and it dose not have any space, it is going to delete some of the old entries that it holds and dose not references recently.(LRU=Least Recently Used) So the remove function is called.

这篇关于凌空DiskBasedCache抛出FileNotFoundException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 13:37