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 ?

3
  • it's loading from url. if you load from cache you also add some mathod.... Commented Feb 1, 2016 at 10:05
  • if think if you have internet connection it will load from url and if else it will show the cache Commented Feb 1, 2016 at 10:05
  • i want to load from cache even if net is present . only 1st time load from net then from cache Commented Feb 2, 2016 at 6:13

2 Answers 2

1

you can check using following method

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

This will let you know about this

Sign up to request clarification or add additional context in comments.

Comments

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

3 Comments

it showing Start display image task [url_45*40] Load image from disk cache [url_45*40] .. so it taking from cache ?
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
what is difference in disk cache and memory ? .cacheOnDisk(true).cacheInMemory(false) is good ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.