nik*_*nik 5 ios restkit restkit-0.20
非常失望的是,restkit已经删除了新版本中的缓存策略.
我们如何在新版本中实现相同的目标?我们是否可以使用现有的restkit类或任何其他方式来实现相同的?
我通过继承RKObjectManager解决了这个问题(如nik答案中链接的第2点所述,但在"Customization&Subclassing Notes"下的文档中有更详细的说明).
我在子类中添加了以下方法,并且没有更多缓存:
- (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;
}
Run Code Online (Sandbox Code Playgroud)
您可以使用 NSMutableURLRequest 创建 RKManagedObjectRequestOperation 并设置 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];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2912 次 |
| 最近记录: |