简体   繁体   English

如何在 Alamofire 请求中检查网络响应来自缓存还是服务器?

[英]How to check network response is from Cache or Server in Alamofire request?

I am making network calls using Alamofire and caching response in iOS app.我正在使用 Alamofire 进行网络调用并在 iOS 应用程序中缓存响应。

response is caching, but I am not able to check whether received response is from Cache or Server?响应正在缓存,但我无法检查收到的响应是来自缓存还是服务器?

How to check the same?如何检查相同?

You can check if there is any cached data for a request is available or not using.您可以检查请求的缓存数据是否可用或未使用。

if let cacheData = URLCache.shared.cachedResponse(for: request) {

  // Already cached
}

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

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