nik
nik

Reputation: 2329

Restkit Cache policy 20.x

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 ?

Upvotes: 5

Views: 2941

Answers (2)

gavdotnet
gavdotnet

Reputation: 2224

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;
}

Upvotes: 6

Numeral
Numeral

Reputation: 1405

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];

Upvotes: 1

Related Questions