Universal Image Loader无法正确缓存

时间:2014-01-01 17:20:28

标签: android caching universal-image-loader

在我的主要活动中,我有一个使用UIL加载图像的viewpager。当我登录我的第一个帐户时,它会显示5个图像并正确下载(在我的缓存文件夹中创建了5个文件)。我尝试再次登录,是的,图像是从光盘加载的。

当我登录我的第二个帐户时,它会加载5个图像,并且第一个帐户有4个相同的图像,所以我希望它只会在我的缓存文件夹中创建1个文件。但是,UIL创建了另外5个文件。

以下是记录这两个帐户后缓存目录的内容:

2 copies of 20 KB file
2 copies of 76 KB file
2 copies of 204 KB file
2 copies of 84 KB file
1 copy of 34 KB file
1 copy of 46 KB file

以下是我的图片加载器的配置:

File cacheDir = StorageUtils.getOwnCacheDirectory(getApplicationContext(), "/cache");
ImageLoader imageLoader = ImageLoader.getInstance();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
        .discCache(new UnlimitedDiscCache(cacheDir))
        .denyCacheImageMultipleSizesInMemory()
        .writeDebugLogs()
        .build();

imageLoader.init(config);
options = new DisplayImageOptions.Builder()
         .showImageOnFail(android.R.drawable.ic_delete)
         .cacheInMemory(true)
         .cacheOnDisc(true)
         .displayer(new RoundedBitmapDisplayer(10))
         .build();

我如何在viewpager的适配器上使用UIL:

@Override
public Object instantiateItem(ViewGroup container, int position) {

    inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View itemView = inflater.inflate(R.layout.header_item, container,false);
    ImageView img = (ImageView) itemView.findViewById(R.id.imageView);
    ProgressBar progressBar = (ProgressBar) itemView.findViewById(R.id.progressBar);
    display(img, list.get(position), progressBar); //list contains the urls
    ((ViewPager) container).addView(itemView);
    return itemView;
}

public void display(ImageView img, String url, final ProgressBar spinner) {
        imageLoader.displayImage(url, img, App.options, new ImageLoadingListener() {
            //progress bar changing visibility
        } );
    }

1 个答案:

答案 0 :(得分:0)

我发现图片是从不同的网址下载的。这是Web开发人员的错,即使图像相同,他也使用不同的链接。

相关问题