0

I'm querying the 'Chat' class to fetch messages from Parse. Then using JSQMessagesViewController to display the fetched messages.

All works fine, until I try to cache the query using:

    query.cachePolicy = .CacheThenNetwork

The issue is the results aren't being cached, and query.hasCachedResult always return false.

The query is as follows:

    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)

And the fetch and JSQMessagesViewController bit is done here:

   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()


            } 
        }

Has anyone for a clue what's wrong with this? .CacheThenNetwork works fine for other queries.

Vertexwahn
  • 7,709
  • 6
  • 64
  • 90
Hassan Mahmood
  • 1,591
  • 2
  • 12
  • 24

1 Answers1

0

So, I found the issue, it was this line with the date parameter:

query.whereKey(PF_CHAT_DELIVERTIME, lessThan: NSDate())

see this answer for more details... https://stackoverflow.com/a/30683459/1250367

Community
  • 1
  • 1
Hassan Mahmood
  • 1,591
  • 2
  • 12
  • 24