Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 毕加索没有从磁盘缓存加载图片_Android_Retrofit_Picasso_Okhttp - Fatal编程技术网

Android 毕加索没有从磁盘缓存加载图片

Android 毕加索没有从磁盘缓存加载图片,android,retrofit,picasso,okhttp,Android,Retrofit,Picasso,Okhttp,我想从互联网上加载一张毕加索的照片,但不连接,从磁盘缓存。缓存正在写入,图片在缓存目录中。但在阅读时,我得到了以下日志: Sending progress READING_FROM_CACHE Cache content not available or expired or disabled 我在我的项目中对请求进行了改造和okhttp。这张图片加载了以下代码: 结果是,如果没有连接,图片不会加载,但图片位于毕加索的缓存目录中,日志显示了该消息 想法 我认为,如果我使用毕加索的自定义下载,

我想从互联网上加载一张毕加索的照片,但不连接,从磁盘缓存。缓存正在写入,图片在缓存目录中。但在阅读时,我得到了以下日志:

Sending progress READING_FROM_CACHE
Cache content not available or expired or disabled
我在我的项目中对请求进行了改造和okhttp。这张图片加载了以下代码:

结果是,如果没有连接,图片不会加载,但图片位于毕加索的缓存目录中,日志显示了该消息

想法

我认为,如果我使用毕加索的自定义下载,我不必修改我的改装请求标题requestintercept->intercept。我有很多帖子和请求,我想让它们保持原样

我检查过的一些链接


提前感谢。

毕加索依靠HTTP层来缓存图像。如果HTTP头不允许缓存,或者缓存时间已过期,则磁盘缓存将无法工作。谢谢您的回答,但我在代码中找不到设置缓存头的位置。请你给我引路好吗?再次感谢。缓存头由服务器返回,除非您控制服务器,否则无法更改。这很有效!谢谢:在这里查看我以前的答案,希望对您有所帮助:[[1]:
// Obtain the cache directory
File cacheDir = getActivity().getCacheDir();

// Create a response cache using the cache directory and size restriction
HttpResponseCache responseCache = null;
try {
    responseCache = new HttpResponseCache(
        cacheDir,
        10 * 1024 * 1024);
} catch (IOException e) {
    e.printStackTrace();
}
// Prepare OkHttp
OkHttpClient httpClient = new OkHttpClient();
httpClient.setResponseCache(responseCache);
// Build Picasso with this custom Downloader
Picasso picasso = new Picasso.Builder(getActivity())
    .downloader(new OkHttpDownloader(httpClient))
    .build();

picasso.setDebugging(true);

picasso.with(getActivity())
    .load(profilePicUrl) // url picture
    .resize(180, 180)
    .centerCrop()
    .placeholder(R.drawable.ic_int_profile_no_photo)
    .into(mProfilePic); //ImageView