0
我在查詢'Chat'類以從Parse中獲取消息。然後使用JSQMessagesViewController顯示提取的消息。解析JSQMessagesViewController緩存問題
一切工作正常,直到我嘗試緩存使用查詢:
query.cachePolicy = .CacheThenNetwork
的問題是結果不被緩存,並query.hasCachedResult總是返回false。
查詢如下:
let query = PFQuery(className: PF_CHAT_CLASS_NAME)
query.whereKey(PF_CHAT_GROUPID, equalTo: forGroupId)
query.whereKey(PF_CHAT_DELIVERTIME, lessThan: NSDate())
query.includeKey(PF_CHAT_USER)
query.orderByDescending(PF_CHAT_DELIVERTIME)
query.limit = 50
query.cachePolicy = .CacheThenNetwork
if query.hasCachedResult{
print("yes")
}
else{
print("no")
}
query.findObjectsInBackgroundWithBlock(completionBlock)
而且獲取和JSQMessagesViewController位都是在這裏完成:
ParseWrapper.getChatAvailable(forGroupId: groupId){
(objects, error) -> Void in
if error == nil {
self.messages.removeAll()
self.users.removeAll()
for object in (objects as [PFObject]!).reverse() {
self.addMessage(object)
}
if objects!.count > 0 {
self.tableViewScrollToBottom(true)
}
self.tableView.reloadData()
self.refreshControl.endRefreshing()
}
}
有沒有人的線索有什麼錯呢? .CacheThenNetwork適用於其他查詢。