简体   繁体   中英

curious about NSURLCache

我对NSURLCache很好奇, NSURLRequest具有某种缓存策略,例如NSURLRequestUseProtocolCachePolicyNSURLRequestReturnCacheDataElseLoad ,但是在读取它们之后,它们中的任何一个都在使用本地缓存数据,或者不使用缓存,我的问题是我是否要首先启动url请求我想加载缓存并呈现ui,然后继续与服务器交互以获取最新数据并刷新ui,我选择哪种策略?

If I understand correctly what you want to achieve (get data quickly from the cache to show in the UI even if it is outdated, then get the current data even if it is slow), you'd have to make two requests, using different cache policies. I'd start the second request only when the first one has finished, and examine the result of the first request first, because the data might not have been available in the cache, so the first request might already returned the uncached data that you wanted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM