Jon
Jon

Reputation: 8021

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

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)..

Upvotes: 34

Views: 22809

Answers (4)

Arnaud
Arnaud

Reputation: 417

Picasso 2.5.0

If you are using Picasso to load image from Internet, you have to use NetworkPolicy attribute.

.networkPolicy(NetworkPolicy.NO_STORE)

but live memory cache (Not disk cache) is useful, you might want to keep it.

Upvotes: 0

Sagar Jethva
Sagar Jethva

Reputation: 1014

For picasso:2.71828 or above version use the following for skipping using disk cache networkPolicy(NetworkPolicy.NO_CACHE) :

  Picasso.get()
            .load(camera_url)
            .placeholder(R.drawable.loader2)
            .networkPolicy(NetworkPolicy.NO_CACHE, NetworkPolicy.NO_STORE)
            .into(img_cam_view);

Upvotes: 8

ahmad dehghan
ahmad dehghan

Reputation: 37

just append this at the end of url.

"?=" + System.currentTimeMillis();

Upvotes: -6

MrEngineer13
MrEngineer13

Reputation: 38856

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.

Upvotes: 71

Related Questions