首页 > 解决方案 > iOS - 禁用 Alamofire 缓存参数

问题描述

Alamofire 是否也缓存请求参数?

完成登录请求后,我打开我的 cache.db,它会显示我的用户名和密码参数。

alamofire 是默认缓存请求参数还是我的配置错误?

有什么方法可以仅为参数禁用缓存。因为目前我只为 .GET 请求启用缓存,因为它没有参数

标签: iosswiftcachingalamofire

解决方案


您可以禁用任何类型的缓存,如下所示,

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    let emptyCache = URLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil)
    URLCache.shared = emptyCache

    return true
}

推荐阅读