使用ktor时检查响应是否来自okhttp缓存

问题描述 投票:0回答:0

我使用以下客户端

private val client: HttpClient by lazy {
    HttpClient(OkHttp) {
        engine {
            config {
                cache(Cache(File(App.context.cacheDir, "ktor"), 10 * 1024 * 1024))
            }
        }

        install(ContentNegotiation) {
            json(jsonSerializer)
        }

        expectSuccess = true
    }
}

...

val response = client.get("https://stuff.com/data")

是否可以检测

response
是否来自okhttp缓存?

我能以某种方式获取 okhttp 响应对象并检查是否

okhttpResponse.networkResponse() == null
吗?

android okhttp ktor ktor-client
© www.soinside.com 2019 - 2024. All rights reserved.