Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to cache preprocessed image on disc #314

Closed
wants to merge 1 commit into from

Conversation

fernandocamargoai
Copy link

Hello,

As promised here #309, I've implemented the functionality and made this pull request.

I've tested this with the app I'm developing. I have a listview that is loaded and paginated from the web. When I loaded too many items, each one with its image (some of the images was repeating), the memory cache was becoming full quickly and it was starting to preprocess all the images again, when I scroll up. It was consuming much CPU and memory... and also giving the user the impression that the image was being loaded again. Now, it's putting the preprocessed image on disc cache. So, it's preprocessing the image just one time and it saved me a lot of CPU and memory. At the moment, I tested to load about 800 items in the ListView. Since some images are repeating, I think it's about 300 unique images in the ListView. When I scroll down, more items are loaded. If I scroll up until reach the top, I see all the images quickly, as if it was loaded instantly. And it's scrolling smoothly.

The way I've implemented, it's not going to break any code that uses this new version. I've included a new option called cachePreProcessedImageOnDisc in the DisplayImageOptions. I think that the user usually would use either cacheOnDisc or cachePreProcessedImageOnDisc. If both are activated, the original image will be loaded from the network to the file and then the file will be overwritten with the preprocessed image.

I hope it's useful.

… possible to cache the original image on disc and the preprocessed image on memory. Now, with a option defined in DisplayImageOptions, it's possible to tell the Universal Image Loader to cache the processed version of the image, so it's not processed again and again everytime it's out of the memory cache.
@derekshi
Copy link

I want to cache 2 versions of the image, one is preprocessed and the other not. I want to pull only preprocessed one if I set ImageDisplayOptions.cachePreProcessedImageOnDisc to true. Any idea?

@fernandocamargoai
Copy link
Author

Well, if you set cacheOnDisc, the original image will be cached. If you set cachePreProcessedImageOnDisc, the preprocessed version will be cached. If you use the same image in different places, sometimes with preprocessing and sometimes without preprocessing, you're in the same situation that me.
By now, I'm using the following workaround:
Since the Universal Image Loader uses the URL to identify the image, I'm appending something in the URL. For example, in my case, I have to show an image of a music's album in a lot of different places with and without preprocessing. If the URL for this image is www.example.com/album/x.jpg, I append an unused parameter for this URL. For example: www.example.com/album/x.jpg?place1, www.example.com/album/x.jpg?place2, etc. This way, the Universal Image Loader thinks it's different images.

In your case, you would set cachePreProcessedImageOnDisc and append something to url when you want to cache the preprocessed version and would set cacheOnDisc and append something else to url when you want to cache the original image.

As I said, it's a workaround. It'd be good to have a way to inform the Universal Image Loader what is the identifier of the image, instead of just using the URL.

@derekshi
Copy link

Thanks, it works well.

@nostra13
Copy link
Owner

Thanks for pull request but I did it my way. I added additional parameter (BitmapProcessor) into ImageLoaderConfiguration.discCacheExtraOptions(...). My solution fit into existing library infrastructure better but it doesn't allow customize processor for different display tasks. Only one global processor for disc cache.
85808ab

@nostra13 nostra13 closed this Jun 27, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants