Java 使用解析服务进行缓存
我无法从Parse.com缓存数据 我一直在读这本书,但我还是很难理解它。如何使用此工具提取数据和缓存Java 使用解析服务进行缓存,java,android,caching,save,Java,Android,Caching,Save,我无法从Parse.com缓存数据 我一直在读这本书,但我还是很难理解它。如何使用此工具提取数据和缓存 query.setCachePolicy(ParseQuery.CachePolicy.NETWORK_ELSE_CACHE); query.findInBackground(new FindCallback<ParseObject>() { public void done(List<ParseObject> scoreList, ParseException e)
query.setCachePolicy(ParseQuery.CachePolicy.NETWORK_ELSE_CACHE);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> scoreList, ParseException e) {
if (e == null) {
// Results were successfully found, looking first on the
// network and then on disk.
} else {
// The network was inaccessible and we have no cached data
// for this query.
}
});
query.setCachePolicy(ParseQuery.CachePolicy.NETWORK\u ELSE\u CACHE);
findInBackground(新的FindCallback(){
已完成公共作废(列表分数列表,Parsee异常){
如果(e==null){
//结果已成功找到,首先查看
//网络,然后在磁盘上。
}否则{
//网络无法访问,我们没有缓存数据
//用于此查询。
}
});
如果指定CachePolicy
,数据将自动缓存在内部存储器上。默认值为CachePolicy。忽略缓存
,因此不会缓存任何数据。由于您对从缓存中获取结果感兴趣,因此使用CachePolicy.CACHE\u ELSE\u网络
更有意义,因此查询将l首先查看缓存内部。您要查找的数据存储在您的案例中的变量scoreList
中
也许你很难理解你的代码是如何工作的,因为你正在使用回调(因为<代码> FiffiBead Su地()/<代码>。请考虑下面的代码:
ParseQuery<Person> personParseQuery = new ParseQuery<Person>(Person.class);
personParseQuery.setCachePolicy(ParseQuery.CachePolicy.CACHE_ELSE_NETWORK);
personParseQuery.addAscendingOrder("sort_order");
List<Person> = personParseQuery.find();
当然,不要忘记首先初始化Parse并注册Person
类:
Parse.initialize(this, "appID", "clientID");
ParseObject.registerSubclass(Person.class);
我希望我的解释能对你有所帮助
PS:执行代码后,通过查看仿真程序上的data.data.your application package+name.cache.com.parse文件夹,可以看到数据被缓存。Hi,你解决了这个问题吗?我也有同样的问题。
Parse.initialize(this, "appID", "clientID");
ParseObject.registerSubclass(Person.class);