简体   繁体   中英

Detect cached response in Alamofire

The app I'm currently working on needs to present a notification to the user only when a networking request returns a non-cached response.

The app uses Alamofire for networking requests.

How can I determine if a response from Alamofire came from the cache or not?

the only way is to check HTTP header fields in HTTP response. Cache-Control field tells all caching mechanisms from server to client whether they may cache this object. It is measured in seconds. Cache-Control: max-age=3600 means that the content of respond can be one hour old.

if you need non cached respond from server, you have to specify Cache-Control field in your request as Cache-Control: no-cache

there is no difference if you are using Alamofire or not

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