简体   繁体   English

如何知道请求是否来自缓存?

[英]How to know If the request came from Cache or not using AFNetworking

This is my first day to me with AFNetworking, I like it :) I've only one question, 这是我使用AFNetworking的第一天,我很喜欢:)我只有一个问题,

I've a request and I cached the response, and set the caching policy, How I could know whether the response data is coming from the cache side or the data is loaded from the originating source ? 我有一个请求,我缓存了响应,并设置了缓存策略,如何知道响应数据是来自缓存端还是从原始源加载了数据?

I need something like 我需要类似的东西

NSLog(@"Cach Used : %@", [request didUseCachedResponse] ? @"YES" : @"NO");

Thanks for your help :) 谢谢你的帮助 :)

There is no way to check in programatically if the response coming from cache or not, if the cache policy is set correctly for hhtp requests, your server response contains a valid Cache-Control header, responses will be automatically cached for subsequent requests. 无法以编程方式签入响应是否来自缓存,如果为hhtp请求正确设置了缓存策略,则您的服务器响应包含有效的Cache-Control标头,则响应将自动缓存为后续请求。 If the response comes from the cache it will be fraction earlier than from the server. 如果响应来自缓存,它将比服务器早。 Here is the link which can give you further info link and AFNetworking FAQ 这是可以为您提供更多信息链接AFNetworking常见问题解答的 链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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