gpt4 book ai didi

ios - IOS应用应该使用什么Cache方式

转载 作者:行者123 更新时间:2023-11-29 00:45:03 25 4
gpt4 key购买 nike

您好,我已经阅读了有关缓存策略的内容,但还是不太清楚。我的目的是设置请求缓存3分钟。响应缓存 3 分钟。保留旧缓存 1 天。我们应该使用什么实现?除了这些默认波纹管之外,还有什么我们可以更改的设置吗? (我使用 AFNetworking 3 进行请求和响应)。非常感谢任何帮助。谢谢

NSURLRequestCachePolicy

NSURLRequest has a cachePolicy property, which specifies the caching behavior of the request according to the following constants:

NSURLRequestUseProtocolCachePolicy: Caching logic defined in the protocol implementation is used for a particular URL load request. This is the default policy.
NSURLRequestReloadIgnoringLocalCacheData: Data should be loaded from the originating source. No existing cache data should be used.
NSURLRequestReloadIgnoringLocalAndRemoteCacheData: Not only should the local cache data be ignored, but proxies and other intermediates should be instructed to disregard their caches so far as the protocol allows.
NSURLRequestReturnCacheDataElseLoad: Existing cached data should be used, regardless of its age or expiration date. If there is no existing data in the cache corresponding to the request, the data is loaded from the originating source.
NSURLRequestReturnCacheDataDontLoad: Existing cache data should be used, regardless of its age or expiration date. If there is no existing data in the cache corresponding to the request, no attempt is made to load the data from the originating source, and the load is considered to have failed, (i.e. “offline” mode).
NSURLRequestReloadRevalidatingCacheData: Existing cache data may be used provided the origin source confirms its validity, otherwise the URL is loaded from the origin source.

最佳答案

你几乎应该总是使用 NSURLRequestUseProtocolCachePolicy 除非你出于某种原因试图完全终止缓存。

缓存持续时间应由服务器设置作为其响应的一部分(在 Cache-Control header 中)。 iOS URL 缓存遵循该 header 中指定的策略。

关于ios - IOS应用应该使用什么Cache方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38716712/

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