Frage

I'm using the "Android universal image loader library (v 1.9.1)" and I'm trying to limit the amount of (disc) cache being used by using this line in a config builder:

.discCache(new TotalSizeLimitedDiscCache(cacheDir, 25 * 1024 * 1024))

I might be doing something really stupid here, but this was supposed to limit my cache to 25MB and when I look at the current App info I'm already at 45+ MB, so it doesn't seem to be working.

Have I missed something?

added suspicion: what if the cache-number also includes the 'memorycache' that is set to true? I working under the assumption this is only a cache as far as the imageLoader is concerned, and from an application/os point of view just another thing using memory. if it isn't, it might explain the numbers?

Complete code for initializing :

private void initImageLoader() {
    DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
        .cacheInMemory(true)
        .cacheOnDisc(true)
        .build();    

     File cacheDir = StorageUtils.getCacheDirectory(getApplicationContext());
     cacheDir.mkdirs(); 


    ImageLoaderConfiguration config = new 
        ImageLoaderConfiguration.Builder(getApplicationContext())
        .defaultDisplayImageOptions(defaultOptions)
        .discCache(new TotalSizeLimitedDiscCache(cacheDir, 25 * 1024 * 1024))
        .build();

    ImageLoader.getInstance().init(config);             
}

And for calling the code (showing imageUrl in imageView)

ImageLoader.getInstance().displayImage(imageUrl, imageView); 
War es hilfreich?

Lösung

When setting the default memory-cache to false (so don't use .cacheInMemory(true)), the cache seems to be keeping itself to the set maximum. The computed cache is probably a combination of the on-disc cache and the memory cache.

This does make the "cache" number from the Android OS somewhat less usable, but on the other hand, it is kinda fair. As it looks like the numbers are lineing up, it's just a matter of setting both maximums, and communicating this to the user.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top