Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)..
like image 610
Jon Avatar asked May 06 '15 20:05

Jon


2 Answers

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.

like image 70
MrEngineer13 Avatar answered Nov 13 '22 20:11

MrEngineer13


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);
like image 34
Sagar Jethva Avatar answered Nov 13 '22 19:11

Sagar Jethva