ios - Alamofire 缓存问题

标签 ios swift caching swift3 alamofire

我在使用 Alamofire 时遇到了一个问题,我对不同的请求得到了相同的响应。我使用以下方法请求:

        self.ephemeralManager?.request("myurladdress.com", headers: headers)
            .authenticate(user: username, password: password)
            .responseJSON { response in
                print(response)
            }

这是 session 管理器:

        let configuration = URLSessionConfiguration.ephemeral
        configuration.urlCache = nil
        ephemeralManager = Alamofire.SessionManager(configuration: configuration)

当我第一次发出请求时,它按预期工作。不久之后,当我使用不同的用户名和密码再次发出请求时,我从上一个请求中获得了响应数据。如果我重新启动应用程序或等待一段时间,请求会按预期工作。

我假设这是一个缓存问题,但在我发出请求之前清除缓存或关闭缓存的所有尝试都失败了。

有什么我想念的吗?我经常使用 Alamofire,从未遇到过这个问题。

Alamofire 版本:4.1 Xcode 版本:8.3.3 swift 版本:3.1 运行 Alamofire 的平台:iOS 运行 Xcode 的 macOS 版本:10.12.5

最佳答案

您可以在发出 alamofire 请求之前清除缓存。

NSURLCache.sharedURLCache().removeAllCachedResponses()

执行此命令后调用 alamofire 请求。

关于ios - Alamofire 缓存问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44976454/

相关文章:

sql-server - DateTime.Now 如何影响 SQL Server 中的查询计划缓存?

ios - 使用 HTML 5 在 iPad 应用程序中自动播放

ios - Swift:无法将 AnyObject 向下转换为 SKPhysicsBody

ios - 如何将 UIImage 正确地锚定到位于自定义单元格中的 UIView 中?

ios - 在构建发布之前清理 Realm 数据库

ios - 如何在不使用 Storyboard的情况下创建新的 Swift 项目?

ios - UITextView.attributedText,如何设置numberOflines和lineBreakMode?

c# - 类型转换成本?

swift - 参数标签 '(itemsCount:)' 不匹配任何可用的重载

javascript - 缓存 uploadify 文件会使 chrome 崩溃