objective-c - NSURLRequests 的默认缓存过期时间是多少?

标签 objective-c ios http caching nsurlrequest

我正在使用 NSURLRequest 检查可用的数据更新。今天我注意到,NSURLRequest 默认缓存请求。即使几个小时后,也没有新的请求发送到服务器。现在我想知道这个缓存的默认行为是什么。缓存的数据什么时候会过时并且新的请求会发送到服务器? 数据是静态文件,服务器不发送显式缓存控制 header :

HTTP/1.1 200 OK<br/> Date: Fri, 13 Apr 2012 08:51:13 GMT<br/> Server: Apache<br/> Last-Modified: Thu, 12 Apr 2012 14:02:17 GMT<br/> ETag: "2852a-64-4bd7bcdba2c40"<br/> Accept-Ranges: bytes<br/> Content-Length: 100<br/> Vary: Accept-Encoding,User-Agent<br/> Content-Type: text/plain

P.S.:我的应用程序的新版本设置了显式缓存策略,因此这不再是问题,但我很好奇默认行为是什么。

最佳答案

备注:here详细说明这应该如何工作

  1. 如果没有缓存则获取数据。

  2. 如果有缓存,则检查加载方案

    一个。如果指定了重新验证,请检查更改源

    如果未指定重新验证,则按照 3) 从本地缓存中获取

  3. 如果未指定重新验证,则检查本地缓存是否足够新。

    一个。如果缓存没有过时,那么它会从缓存中提取数据

    如果数据过时,则从源重新验证

来自 here :

The default cache policy for an NSURLRequest instance is NSURLRequestUseProtocolCachePolicy. The NSURLRequestUseProtocolCachePolicy behavior is protocol specific and is defined as being the best conforming policy for the protocol

来自 here :

If an NSCachedURLResponse does not exist for the request, then the data is fetched from the originating source. If there is a cached response for the request, the URL loading system checks the response to determine if it specifies that the contents must be revalidated. If the contents must be revalidated a connection is made to the originating source to see if it has changed. If it has not changed, then the response is returned from the local cache. If it has changed, the data is fetched from the originating source.

If the cached response doesn’t specify that the contents must be revalidated, the maximum age or expiration specified in the response is examined. If the cached response is recent enough, then the response is returned from the local cache. If the response is determined to be stale, the originating source is checked for newer data. If newer data is available, the data is fetched from the originating source, otherwise it is returned from the cache.

列出的其他选项 here .

关于objective-c - NSURLRequests 的默认缓存过期时间是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10138101/

相关文章:

rest - 公开记录开放 API 是一种好习惯吗?

iphone - 返回 PHP 网页生成的字符串

ios - 返回了无效的JSON:无法解析为[String:String],但可以作为NSArray使用

java - 通过 Java 套接字发送带有 <APPLET> 标记的 html 文件

ios - UIPageViewController 手势正在调用 viewControllerAfter : but doesn't animate

objective-c - MPMoviePlayerController 不播放视频

javascript - 如何在服务中进行http调用但得到 Controller 的响应? AngularJS

ios - 分享后如何从 Instagram 应用程序重定向到我的 iOS 应用程序

ios - 如何在 Obj-C 的运行时中将结构与对象相关联

ios - 同时更改所有表格 View 单元格上的显示参数