0

I had come across, the libraries like volley for web-service call and picasso for images. Both, uses cache to save data.

How exactly the caching works, with these libraries. Let's say after api call, the data is cached using volley, will it be available in all other activities, while switching back and forth?

If once, the data is fetched and saved in cache using volley in activity A and then i switch to activity B and when i come back to A, will the cached data will be used by the volley or a new request will be fired.

Suppose, if it used the cached data, then in the scenario where the data-set is changed on the server,in such scenario how the new data set will appear on device.

Same with Picasso.

Any help or suggestion would be appreciated,as i am new to android.

Ritt
  • 3,181
  • 3
  • 22
  • 51
  • I haven't worked with volley but Picasso will cache your all images. Despite of volley Retrofit is a good option for caching and making REST call. For retrofit / Rx-java / Picasso check out this : https://www.reddit.com/r/androiddev/comments/35yyud/a_good_approach_for_caching_and_cookies_with/ – Amit Pal Oct 19 '15 at 21:10
  • cache all the images? Does that means no network request after coming back from some other activity to the activity where picasso is used? Does that also means, after you stop, the app and restart again, the cached image will be used by picasso without net connection? – Ritt Oct 19 '15 at 21:13
  • 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). Check out the Jake answer http://stackoverflow.com/questions/23280242/using-picasso-with-custom-disk-cache – Amit Pal Oct 19 '15 at 21:16
  • thank you @AmitPal, it did cleared my doubt. just to make sure if i have got right, picasso uses http client cache, i.e it will fire a request and only that requests will hit server, which is not there in the http client cache. correct me if i am wrong. – Ritt Oct 19 '15 at 21:34
  • yes, You are correct – Amit Pal Oct 19 '15 at 21:47
  • okay, now let' say i am using some url like "http://example.com" to get images using picasso in activity A which is called on onStart() method, and then i switch to activity B and i disable my net connection and switch back to activity A, and it fires the same request, as it's called in onstart() method.Will it work in this scenario, without net connection because images are already cached. – Ritt Oct 19 '15 at 21:52
  • In my opinion it should work. Do you want to give a try to test the feature? – Amit Pal Oct 19 '15 at 21:59
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/92776/discussion-between-ritesh-and-amit-pal). – Ritt Oct 19 '15 at 21:59

0 Answers0