【问题标题】:Detect cached response in Alamofire在 Alamofire 中检测缓存的响应
【发布时间】:2023-03-13 05:15:01
【问题描述】:

仅当网络请求返回非缓存响应时,我当前正在开发的应用程序才需要向用户显示通知。

该应用使用 Alamofire 进行网络请求。

如何确定来自 Alamofire 的响应是否来自缓存?

【问题讨论】:

    标签: ios swift caching swift2 alamofire


    【解决方案1】:

    唯一的方法是在 HTTP 响应中检查 HTTP header fields。 Cache-Control 字段告诉从服务器到客户端的所有缓存机制它们是否可以缓存此对象。它以秒为单位。 Cache-Control: max-age=3600 表示响应的内容可以是一小时前的。

    如果您需要来自服务器的非缓存响应,您必须在请求中指定 Cache-Control 字段为 Cache-Control: no-cache

    是否使用 Alamofire 没有区别

    【讨论】:

      猜你喜欢
      • 2016-12-08
      • 2020-01-06
      • 1970-01-01
      • 1970-01-01
      • 2021-09-22
      • 1970-01-01
      • 2019-04-30
      • 1970-01-01
      • 2016-01-11
      相关资源
      最近更新 更多