0

Im using Picasso and okhttp to download and cache images onto the disk. Im using the below code snippet to set a cache of 10MB to the okhttp client and using it for Picasso.

File folder = new File(context.getCacheDir(),"HomePageCache");
if (!folder.exists())
   folder.mkdir();
okHttpClient.setCache(new com.squareup.okhttp.Cache(folder, 1024 * 1024 * 10));
OkHttpDownloader okHttpDownloader = new OkHttpDownloader(okHttpClient);
picasso = new com.squareup.picasso.Picasso.Builder(context).indicatorsEnabled(true).downloader(okHttpDownloader).build();

This is working perfectly most of the time caching and reloading images even when offline , but the problem is that sometimes it just clears the image cache completely.

I am checking the size of the image cache just to be sure, and it has never crossed 2 MB.

Is there any other reason why my cache is getting cleared?

4

1 回答 1

0

就像Nikola在评论中指出的那样,缓存过期标头负责使缓存的图像失效。

于 2017-10-22T13:56:30.663 回答