如何使用 picasso 库 - Android 实现我自己的磁盘缓存? [英] How to implement my own disk cache with picasso library - Android?

查看:26
本文介绍了如何使用 picasso 库 - Android 实现我自己的磁盘缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 picasso 库为我的应用加载图像.但是我不知道如何使用 picasso 库实现我自己的磁盘(sdcard)缓存.

I'm using picasso library to load images for my app. But I don't how to implement my own disk (sdcard) caching with picasso library.

推荐答案

Picasso 使用 HTTP 客户端进行磁盘缓存,如果已经配置了它,它将使用它而不是安装自己的.

Picasso uses the HTTP client for disk caching and if one is already configured it will use that instead of installing its own.

对于内置的 UrlConnection,安装缓存的文档在这里:https://developer.android.com/reference/android/net/http/HttpResponseCache.html

For the built-in UrlConnection the docs for installing a cache are here: https://developer.android.com/reference/android/net/http/HttpResponseCache.html

如果您使用 OkHttp,那么您只需调用 setCache:http://square.github.io/okhttp/2.x/okhttp/com/squareup/okhttp/OkHttpClient.html#setCache-com.squareup.okhttp.Cache-

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 库 - Android 实现我自己的磁盘缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆