Using Picasso with custom disk cache
Picasso doesn't have a disk cache. It delegates to whatever HTTP client you are using for that functionality (relying on HTTP cache semantics for cache control). Because of this, the behavior you seek comes for free.
The underlying HTTP client will only download an image over the network if one does not exist in its local cache (and that image isn't expired).
That said, you can create custom cache implementation for java.net.HttpUrlConnection
(via ResponseCache
or OkHttp (via ResponseCache
or OkResponseCache
) which stores files in the format you desire. I would strongly advise against this, however.
Let Picasso and the HTTP client do the work for you!
You can call setIndicatorsEnabled(true)
on the Picasso
instance to see an indicator from where images are being loaded. It looks like this:
If you never see a blue indicator, it's likely that your remote images do not include proper cache headers to enable caching to disk.
How to implement my own disk cache with picasso library - Android?
Picasso uses the HTTP client for disk caching and if one is already configured it will use that instead of installing its own.
For the built-in UrlConnection the docs for installing a cache are here: https://developer.android.com/reference/android/net/http/HttpResponseCache.html
If you are using OkHttp then you just call setCache:
http://square.github.io/okhttp/2.x/okhttp/com/squareup/okhttp/OkHttpClient.html#setCache-com.squareup.okhttp.Cache-
Picasso doesn't cache image on disk
Ah since this is happening when you change headers, you are most probably not setting the Cache-Control header
According to Jake wharton (One of the developer of Picasso)
Picasso doesn't have a disk cache. It delegates to whatever HTTP
client you are using for that functionality (relying on HTTP cache
semantics for cache control). Because of this, the behavior you seek
comes for free
Taken from Jake Wharton's answer here
Also,
If you never see a blue indicator, it's likely that your remote images
do not include proper cache headers to enable caching to disk
Picasso - keeping images on disk
You can iterate the elements in OkHttp's disk cache, and call Iterator.remove()
to get rid of the ones you don't want.
http://square.github.io/okhttp/javadoc/com/squareup/okhttp/Cache.html#urls--
Related Topics
What's Oncreate(Bundle Savedinstancestate)
Add "View More" at the End of Textview After 3 Lines
When to Register/Unregister Broadcast Receivers Created in an Activity
Failed to Resolve Com.Android.Support:Appcompat-V7:22 and Com.Android.Support:Recyclerview-V7:21.1.2
Sniffing/Logging Your Own Android Bluetooth Traffic
Android Compass That Can Compensate for Tilt and Pitch
New Intent() Starts New Instance with Android: Launchmode="Singletop"
How to Use Custom Permissions in Android
How to Use Getsystemservice in a Non-Activity Class (Locationmanager)
Drawerlayout Double Drawer (Left and Right Drawers Simultaneously)
How to Create a Resizable Rectangle with User Touch Events on Android
How to Check Which Notifications Are Active in Status Bar in Android Dev
Change the Text Color of Numberpicker
Android Save View to Jpg or Png
How to Set a Particular Font for a Button Text in Android