1
votes

So I have a strange problem and I'm not sure what is happening here. When the app first loads it requests the objects and maps them just fine. On reload or launching the app again RestKit appears to only be returning the original mapped objects on app load, If I delete the app and build again all original objects and any new ones are returned.

I have tested with curl by adding new objects after the initial app load. So say if when I loaded the app with 5 objects, then I add 2 more the call with curl to the same service will be correct with 7 objects returned, while Restkit is still only returning 5 in the app.

Currently I'm using this method, could it be something to do with my managed contexts? Any help would be useful.

RKManagedObjectRequestOperation *operation = [[RKObjectManager sharedManager] managedObjectRequestOperationWithRequest:request
                                                                                                           managedObjectContext:[RKObjectManager sharedManager].managedObjectStore.mainQueueManagedObjectContext
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
     // Create dictionary to pass as userinfo with returned object
     NSDictionary *userInfo = [[NSDictionary alloc] initWithObjects:@[mappingResult] forKeys:@[ OBJECT_FROM_SERVER ]];
     [[NSNotificationCenter defaultCenter] postNotificationName:notificationName object:nil userInfo:userInfo];
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
}];

EDIT: I should also add that server logs confirm that Restkit is not hitting the server after initial app load, but it is calling the same method to fetch the results.

Edit2: Ok so I noticed something very strange, not sure if this is expected behaviour. As I stated below after the first contact of my webservice RestKit doesn't even bother with the webservice, but rather pulls data from core data using the quoted method. Using any getObjects method actually contacts the server every time? Is this expected behaviour?? The docs sure don't reflect that unless I missed something.

Server: Apache-Coyote/1.1
Cache-Control: public, max-age=86400
Content-Type: application/json
Content-Length: 1629
Date: Sun, 20 Oct 2013 22:43:20 GMT
1
Is your server returning any cache headers? Are you changing the request/response descriptors in between calls? - Wain
Nope, Restkit doesn't even contact the server with that method. Have a look at my edits. - Michael
If it calls the server once then that will return headers, what are they? - Wain
Added it to the original question as it is easier to read - Michael

1 Answers

2
votes

Your server returns a cache header:

Cache-Control: public, max-age=86400

This means that the URL loading system won't hit the server again for the same request for 1 day. Instead, the cached value will be used. This is the cache in the URL loading system, not in RestKit.

If you want to hit the server each time a request is made, change the cache response from the server or set the URL loading system to ignore the cache.