33

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)..
Jon
  • 7,941
  • 9
  • 53
  • 105

4 Answers4

70

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.

MrEngineer13
  • 38,642
  • 13
  • 74
  • 93
8

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);
Community
  • 1
  • 1
Sagar Jethva
  • 986
  • 12
  • 26
  • 1
    `NetworkPolicy` regulates the disk cache as compared to MemoryPolicy which regulates the memory cache. Additionally `NetworkPolicy.NO_STORE` flag can also be used to skip storing the images on the disk. – Amit Dash Apr 17 '19 at 06:36
0

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.

Arnaud
  • 408
  • 4
  • 11
-6

just append this at the end of url.

"?=" + System.currentTimeMillis();
ahmad dehghan
  • 37
  • 1
  • 3