OGeek|极客世界-中国程序员成长平台

标题: ios - AFNetworking 禁用缓存 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 03:19
标题: ios - AFNetworking 禁用缓存

我正在尝试从服务器获取 JSON 文件,然后将其显示在表格中,这可以正常工作,但是,出于某种原因,AFNetworking 即使在应用重新启动后也会缓存 JSON 文件。 如何禁用此功能?

 NSURL *url = [NSURL URLWithString"http://?json"];

    NSURLRequest *request = [NSURLRequest requestWithURL:url];

    AFJSONRequestOperation *operation = [AFJSONRequestOperation
                                         JSONRequestOperationWithRequest:request
                                         success:^(NSURLRequest *request, NSHTTPURLResponse *response, id responseObject)
                                         {

                                             self.dataget = [responseObject objectForKey"data"];
                                             [self.tableView reloadData];


                                         }
                                         failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id responseObject)
                                         {

                                             [HUD hideUIBlockingIndicator];
                                         }];

    [operation start];

json 文件可能没有缓存在服务器端: 缓存控制:无缓存[CRLF]



Best Answer-推荐答案


可以在 NSMutableURLRequest 对象上设置缓存行为,使用 setCachePolicy:。否则,内置共享 NSURLCache 将尊重服务器定义的缓存行为(我建议调整和利用,而不是完全无视)。

关于ios - AFNetworking 禁用缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18127124/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4