标准方法在Android中缓存数据?缓存、标准、方法、数据

2023-09-05 08:24:13 作者:脸美逼受罪@

我有点困惑如何在Android的高速缓存数据。我见过很多人实现自己的高速缓存(例如,在的 droidfu 项目),而Android似乎有它自己的缓存系统的 ResponseCache中。

I'm a bit confused about how to cache data in Android. I've seen many people implementing their own cache (eg, in droidfu project), but Android seems to have its own caching system with ResponseCache.

有什么理由不采用Android缓存?

Is there any reason for not using Android cache?

什么是缓存的URLConnection响应(文字,数据,JSON ...)的标准方法,我在哪里可以找到例子?

What's the standard way to cache URLConnection response (text, data, json...), and where can I found examples?

感谢

推荐答案

您已经在高速缓存的大小或对象时,被清除(据我所知)无法控制 您不能设置缓存到SD卡

对于小型网络服务请求的 ResponseCache中就足够了,并且是缓存的原始响应的标准方法。当你需要有自己的缓存较大的物体打交道这是唯一真正

For small web-service requests the ResponseCache will suffice, and is the standard way of caching the raw response. It is only really when dealing with larger objects that you will need your own cache.

另外,您可以

序列化数据并将其保存到本地文件 有关的基本数据,你可以将其保存在共享preferences 如果是长寿命 Serialize the data and save it to a local file For basic data you could save it in SharedPreferences if it is long-lived