如何实现缓存为REST API的结果Android应用程序?缓存、如何实现、应用程序、结果

2023-09-04 03:50:23 作者:超软超可爱

使用REST API我的Andr​​oid应用程序获取数据。我想有客户端缓存来实现。难道我们有什么内在的班呢?

My android app gets its data using REST API. I want to have client side caching implemented. Do we have any inbuilt classes for this?

如果不是,这是任何code,我可以重用?我记得满眼都是code的某个时候回来。不过,我不能找到它。

if not, is these any code that i can reuse? I remember coming across such code sometime back. However I cant find it.

如果没有其他的作品,我会写我自己的。以下是基本结构

If nothing else works, i will write my own. following is basic structure

public class MyCacheManager {

static Map<String, Object> mycache;

public static Object getData(String cacheid) {
    return mycache.get(cacheid);
}

public static void putData(String cacheid, Object obj, int time) {
    mycache.put(cacheid, obj);
}

}

如何启用时间缓存对象?还有 - 最新最好的方式来序列化?即使应用程序被关闭并重新打开后缓存应该是完好的(如果时间还没有过期)。

how do i enable time for cached objects? also - whats the best way to serialize? cache should be intact even if app is closed and reopened later (if time has not expired).

谢谢 阿贾伊

推荐答案

发布的谷歌现在我真棒库排球/ O 2013,这有助于为改善对调用REST API的所有问题:

Now awesome library Volley released on Google I/O 2013 which helps for improve over all problems of calling REST API:

排球是一个库 ,这是图书馆称为从排球Android的开发团队。这使得网络的Andr​​oid应用程序更容易,最重要的是,速度更快。它管理的加工和缓存网络请求的,它为开发人员节约了宝贵的时间从C一遍又一遍写在同一个网络的呼叫/缓存$ C $。而具有较少code的一个好处是臭虫数量少,这是所有开发者想要的瞄准。

Volley is a library,it is library called Volley from the Android dev team. that makes networking for Android apps easier and most importantly, faster. It manages the processing and caching of network requests and it saves developers valuable time from writing the same network call/cache code again and again. And one more benefit of having less code is less number of bugs and that’s all developers want and aim for.

实例凌空: technotalkative