1

I implemented a routine which saves data from a json into database and after that if user gets offline, he can see all data. but picasso doesn't load the images after the first run. but when i run the application twice in online mode, after that picasso can load the images from cache in offline mode. (it should cache images on the first run but it's not working)

appreciate any suggestion

masoud vali
  • 1,528
  • 2
  • 18
  • 29

2 Answers2

3

https://stackoverflow.com/a/23281195/3664628

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

Community
  • 1
  • 1
Leonid Veremchuk
  • 1,952
  • 15
  • 27
-1

The main reason may be other images are evicting the older ones from the cache due to their size. You can load smaller versions or increase the size of the memory cache like this

Picasso p = new Picasso.Builder(context)
.memoryCache(new LruCache(Size))
.build();

If you don't want to save in cache, You can Additionally exclude that too using Memory Policy.

Picasso attempts to get the requested image from the memory first. If you would like Picasso to skip this step, you can call memoryPolicy(MemoryPolicy policy, MemoryPolicy... additional) on your Picasso request creator. MemoryPolicy is a simple enum with two values: NO_CACHE and NO_STORE. like this

Picasso
.with(context)
.load(UsageExampleListViewAdapter.eatFoodyImages[1])
.memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)
.into(imageViewFromDisk);

Additional Source : futurestud.io

Shree Krishna
  • 8,474
  • 6
  • 40
  • 68
  • your answer is completely against what i want. i want disk cache in my application – masoud vali Mar 07 '16 at 04:43
  • @masoudvali it's not against your question bro, The below part is just an extra info, Read first line, and there is info why your image may not be cached. It's may be because your image was too large or the cache size was too small. I clearly defined that. – Shree Krishna Mar 08 '16 at 04:14