"error: This object is not available in the offline cache" occurs only some times with Parse backend
Asked Answered
P

4

7

i currently added parse backend to my ios project and defined it to work with its local data storage. it all seems to work fine except of sometimes i receive "This object is not available in the offline cache" all tough as far as i understood there is no cache at all when using local data store (enabling it in my AppDelegate like this: [Parse enableLocalDatastore];). the problem is if i reopen the app, eventually that object will be retrieved successfully. has anyone encountered this problem before?

EDIT: the order of calls i do is

PFQuery *query = [PFQuery queryWithClassName:className];
[query fromLocalDatastore];
[query whereKey:someKey equalTo:someObject];
[query includeKey:@"someKey1"];
[query includeKey:@"someKey2"];
[query orderByAscending:@"date"];
[query findObjectsInBackground];

its built for ios sdk 8.0 and parse sdk 1.7.2

thanks!

Pompei answered 7/6, 2015 at 16:22 Comment(4)
Same problem here. Doesn't happen if I make this query after an online query (where I put the includeKey as well) but after dismissing the app and restarting it, the local query (without foregoing online refresh) fails with this error.Disbursement
Same issue after 2nd query to same object class but with different criteria. The query includes an array relationship.Anglin
I have the same problem as of version 1.7.5.Warbeck
Did anyone find a solution for this? Same thing happening to me.Overuse
I
1

You need to create a strong reference of that unavailable object prior to pinning a different object to the local datastore. Without the strong reference, the object will be flushed out from the offline cache, even though the current and different object you pinned will be saved. Hence when you re-query, you get the error message above.

Inaccessible answered 11/10, 2015 at 12:19 Comment(0)
C
1

I had the same issue. My reason was that I pinned same query objects with same name at two places in my code. When I remove pin with name function and simply pin them. All work fine for me.

Cardioid answered 28/12, 2015 at 12:26 Comment(0)
E
0

Ensure that you have also pinned any of the objects which may be related to the query by calling

[query includeKey:@"someKey1"];

for all pointers to all objects which may be needed.

Effortful answered 28/11, 2015 at 19:17 Comment(0)
A
0

I received this error while using parse live query. I found that whenever an object was "updated" via my live query, it needed to be FULLY repinned to get this error to go away. I am pinning with names. Here's my function to repin.

extension PFObject {
func repin(className:String, completion: @escaping () -> Void) {
    self.unpinInBackground(withName: className) { (success, error) in
        if let error = error {
            print(error)
        } else {
            self.pinInBackground(withName: className) { (success, error) in
                if let error = error {
                    print(error)
                } else {
                    completion()
                }
            }
        }
    }
}
}
Ashworth answered 26/8, 2020 at 19:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.