bob
bob

Reputation: 155

Caching Imager using UNIVERSAL IMAGE LOADER

I am trying to cache image using universal image loader

DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder().cacheOnDisk(true).cacheInMemory(true).imageScaleType(ImageScaleType.EXACTLY).resetViewBeforeLoading(true)
            .displayer(new BitmapDisplayer(100)).bitmapConfig(Bitmap.Config.RGB_565).build();

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()).defaultDisplayImageOptions(defaultOptions).memoryCache(new WeakMemoryCache())
            .diskCacheSize(10 * 1024 * 1024).build();

ImageLoader.getInstance().init(config);

for display images

ImageLoader.getInstance().displayImage(imageUrl, imageview,defaultOptions);

now I can come to know that images are loading from cache or from url ?

Upvotes: 1

Views: 126

Answers (2)

Linh
Linh

Reputation: 60923

You can add config.writeDebugLogs(); to your Universal Image Loader config

ImageLoaderConfiguration.Builder config = new    ImageLoaderConfiguration.Builder(context);
        config.threadPriority(Thread.NORM_PRIORITY - 2);
        config.denyCacheImageMultipleSizesInMemory();
        config.diskCacheFileNameGenerator(new Md5FileNameGenerator());
        config.diskCacheSize(50 * 1024 * 1024); // 50 MiB
        config.tasksProcessingOrder(QueueProcessingType.LIFO);
        config.writeDebugLogs(); // Remove for release app

        // Initialize ImageLoader with configuration.
        ImageLoader.getInstance().init(config.build());

Then when you load image, check the logcat to know that image is loading from cache or from url

Upvotes: 0

Punit Sharma
Punit Sharma

Reputation: 2947

you can check using following method

MemoryCacheUtils.findCachedBitmapsForImageUri(imageUri, ImageLoader.getInstance().getMemoryCache());

This will let you know about this

Upvotes: 1

Related Questions