代码如下,测试了多次都没有缓存:
func getStatus(completion:@escaping (_ list:[LCStatus])->()){
let query = LCStatus.inboxQuery(kLCStatusTypeTimeline)
// 查询结果的排序,按创建时间的降序排列
query.order(byDescending: "createdAt")
// 设置缓存
query.cachePolicy = .networkElseCache
query.maxCacheAge = 24*3600
query.limit = 1
query.findObjectsInBackground { (results, error) in
if ((error == nil)){
if let results = results as? [LCStatus]{
let list = results
completion(list )
}else{
print(error ?? "未知错误")
}
}else{
}
}
}