Android - use picasso to load image without storing it in cache

Jon picture Jon · May 6, 2015 · Viewed 19k times · Source

I want to use picasso to load an image from a url into a placeholder, but not store that image in cache - in other words, I want the image to be downloaded from the net directly to disk and then loaded from disk when needed. I understand there's a class called RequestCreator where you can specify memory policy - does anyone have an example of using picasso/requestcreator to do something like this?

So.. something like:

RequestCreator requestCreator = new RequestCreator();
requestCreator.memoryPolicy(MemoryPolicy.NO_CACHE);
....

merged with:

Picasso.with(context).load(someurl).fit().placeholder(someplaceholder).into(sometarget)..

Answer

MrEngineer13 picture MrEngineer13 · May 6, 2015

Picasso supports this by it's skipMemoryCache() in the Picasso builder. An example is shown below.

Picasso.with(context).load(imageUrl)
                .error(R.drawable.error)
                .placeholder(R.drawable.placeholder)
                .skipMemoryCache()
                .into(imageView);

With the new API you should use it like this so that it skips looking for it and storing it in the cache:

Picasso.with(context).load(imageUrl)
            .error(R.drawable.error)
            .placeholder(R.drawable.placeholder)
            .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)
            .into(imageView);

NO_CACHE

Skips memory cache lookup when processing a request.

NO_STORE

Skips storing the final result into memory cache. Useful for one-off requests to avoid evicting other bitmaps from the cache.