5

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 ?

nik
  • 2,289
  • 6
  • 37
  • 60
  • RestKit uses AFNetworking so standard URL handling caches will be used. What are you trying to do and what doesn't work? – Wain Jul 01 '13 at 10:24
  • 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 Jul 01 '13 at 10:32
  • found a useful answers, Solution [here](https://groups.google.com/forum/#!topic/restkit/Va8sPGF7MyE) – nik Jul 08 '13 at 14:26

2 Answers2

6

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;
}
gavdotnet
  • 2,214
  • 1
  • 20
  • 30
  • I think as of v0.20.3 the method to override is requestWithMethod:path:parameters: just adding the "request.cachePolicy = NSURLRequestReloadIgnoringLocalAndRemoteCacheData;" before the "return request;" – jbcaveman Aug 12 '14 at 12:08
1

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];
Numeral
  • 1,405
  • 12
  • 24
  • is it I can customise this request cache policy like cachetimeout, duration etc.. ?? – nik Jul 01 '13 at 10:50