5
votes

Am very much disappointed in that restkit has removed the cache policy in their newer version.

How we can achieve the same in newer version? and is it possible can we use existing restkit classes for this Or any other way to implement the same ?

2
RestKit uses AFNetworking so standard URL handling caches will be used. What are you trying to do and what doesn't work? - Wain
In earlier version I have created a wrapper which will also do cache the POST request Response. I was simply assigning the value to a request like cachetimeout, duration etc.. - nik
found a useful answers, Solution here - nik

2 Answers

6
votes

I solved this problem by subclassing RKObjectManager (as outlined in the 2nd point in the link in nik's answer but specified in a little more detail in the docs under "Customization & Subclassing Notes").

I added the following method to the subclass and there was no more caching:

- (NSMutableURLRequest *)requestWithObject:(id)object method:(RKRequestMethod)method path:(NSString *)path parameters:(NSDictionary *)parameters
{
    NSMutableURLRequest *request = [super requestWithObject:object method:method path:path parameters:parameters];
    request.cachePolicy = NSURLRequestReloadIgnoringLocalAndRemoteCacheData;
    return request;
}
1
votes

You can create RKManagedObjectRequestOperation with NSMutableURLRequest and set request.cachePolicy:

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:path relativeToURL:self.baseURL]];

request.cachePolicy = NSURLRequestReloadIgnoringLocalAndRemoteCacheData;

RKManagedObjectRequestOperation *operation = [[RKManagedObjectRequestOperation alloc] initWithRequest:request responseDescriptors:[RKObjectManager sharedManager].responseDescriptors];
operation.managedObjectContext = [[RKManagedObjectStore defaultStore] newChildManagedObjectContextWithConcurrencyType:NSPrivateQueueConcurrencyType tracksChanges:YES];
operation.managedObjectCache = [RKManagedObjectStore defaultStore].managedObjectCache;

[operation setCompletionBlockWithSuccess:success failure:failure];

NSOperationQueue *operationQueue = [NSOperationQueue new];
[operationQueue addOperation:operation];