AFNetworking - 不缓存响应 [英] AFNetworking - do not cache response
问题描述
我正在使用此代码从服务器提取一个简单的 JSON 提要:
I'm using this code to pull a simple JSON feed from a server:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager GET:kDataUrl parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"response: %@", responseObject);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"JSON DataError: %@", error);
}];
它有效.但是,在我更改 kDataUrl
处的 JSON 文件并验证更改是在浏览器中进行后,当我再次运行该应用程序时,我仍然收到之前的响应.
It works. However, after I change the JSON file at kDataUrl
, and verify that the change is made in a browser, when I run the app again, I still get the previous response.
似乎 AFNetworking 正在以某种方式缓存旧响应.我不想要这种行为.我想下载当前的提要.是否需要设置某种设置或参数来关闭缓存?
It seems that AFNetworking is somehow caching the old response. I do not want this behavior. I want to download the current feed. Is there some kind of setting or parameter I need to set to turn off caching?
推荐答案
长话短说,只需定义您的 AFNetworking 经理:
Make long story short, just define your AFNetworking manager:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager.requestSerializer setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
享受吧!
这篇关于AFNetworking - 不缓存响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!