1

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 ?

Chintan Bawa
  • 1,376
  • 11
  • 15
bob
  • 155
  • 3
  • 13

2 Answers2

1

you can check using following method

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

This will let you know about this

Punit Sharma
  • 2,951
  • 1
  • 20
  • 35
0

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

Linh
  • 57,942
  • 23
  • 262
  • 279
  • it showing Start display image task [https://url_45*40] Load image from disk cache [https://url_45*40] .. so it taking from cache ? – bob Feb 02 '16 at 06:30
  • when you cache image then this image can loaded without internet. and if you don't cache, everytime you load image, you need to connect to internet. Depend on your purpose, you should choose cache or not cache – Linh Feb 02 '16 at 06:44
  • what is difference in disk cache and memory ? .cacheOnDisk(true).cacheInMemory(false) is good ? – bob Feb 02 '16 at 06:59