gpt4 book ai didi

ios - 缓存控制 : max-age does not make AFNetworking cache the response

转载 作者:可可西里 更新时间:2023-11-01 06:05:30 27 4
gpt4 key购买 nike

在服务器端,我正在设置 Cache-Control:max-age=14400。

在我的 iOS 客户端中,我正在设置 AFHTTPSessionManager 的共享实例,如下所示:

+ (TKClient *)sharedInstance {
static TKClient *instance = nil;
static dispatch_once_t token;

dispatch_once(&token, ^ {
instance = [[TKClient alloc] initWithBaseURL:[NSURL URLWithString:kTKBaseUrl]];
[instance setRequestSerializer:[AFJSONRequestSerializer serializer]];
});

return instance;

然后像这样调用我的 API:

- (void)listingsWithParams:(NSDictionary *)params completion:(void (^)(NSMutableArray *listings, NSError *error))completion {
[self GET:@"api/listings" parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
// success here
} failure:^(NSURLSessionDataTask *task, NSError *error) {
// error here
}];

我已验证此列表调用的缓存控制 header 已从服务器端正确返回。但是,调用每次都会转到服务器,而且显然没有被缓存。知道问题出在哪里吗?

我是否需要在 iOS 端配置其他东西,或者以某种方式更改 Cache-Control header ?谢谢!

最佳答案

尝试添加这个:

[connectionManager.requestSerializer setCachePolicy:NSURLRequestReturnCacheDataElseLoad];

编辑如果您已完成所有操作,请再次检查 header ,也许您在 API 上遗漏了一些东西!也许你应该使用 "Cache-Control"= "public, max-age=14400";public 关键字添加到 Cache-Control header ?

public 表示响应可以被任何缓存缓存,即使它通常是不可缓存的或只能在非共享缓存中缓存。

关于ios - 缓存控制 : max-age does not make AFNetworking cache the response,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31691910/

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