gpt4 book ai didi

ios - AFNetworking 2.0 和 Nginx 之间的文件缓存

转载 作者:行者123 更新时间:2023-12-01 19:04:21 24 4
gpt4 key购买 nike

iOS客户端:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"host/json/demo.json"
parameters:parameters
success:^(AFHTTPRequestOperation *operation, id responseObject) {

}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {

}];

服务器上的 Nginx conf:
location /json {
alias /var/www/json;
expires 30s;
}

我第一次运行应用程序并从服务器正确获取json数据,然后我修改服务器上的demo.json,重新启动应用程序,我仍然得到 json 数据(甚至 30 秒后),但在终端中使用 CURL 推荐我可以获得 json 数据。我删除应用程序并重新安装它,然后我得到 json数据。
我的 conf 或代码有问题吗?

最佳答案

您的服务器对您的 GET 请求的响应包含 cache-control HTTP headers ,导致基础 URL 加载系统缓存您的请求。见NSURLCache Class Reference (和 this NSHipster article about it )以了解更多信息。

在调试期间,您可以暂时禁用缓存:

NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0
diskCapacity:0
diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];

但这绝对不建议在大多数生产应用程序中使用,因为缓存对于移动设备上的网络性能非常重要。

如果存在不应缓存的特定资源,则服务器应使用缓存控制 header 指示这些资源。

关于ios - AFNetworking 2.0 和 Nginx 之间的文件缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20725890/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com