question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ktor Client HTTP Cache

See original GitHub issue

Ktor Version

Ktor 1.1.3

Ktor Engine Used(client or server and name)

Ktor Client iOS engine

JVM Version, Operating System and Relevant Context

Feedback

I’m building a multi-platform (Android and iOS) kotlin project, using ktor client, and i want to have HTTP cache implemented. For android i’m using the OKHTTP client, and configuring the Cache using the HttpConfig.

In iOS i was expecting to have the default caching policy, but in the code, https://github.com/ktorio/ktor/blob/0b3548afa30ff11d13c7496c0047465a6825682f/ktor-client/ktor-client-ios/darwin/src/io/ktor/client/engine/ios/IosClientEngine.kt#L86 it is being set to NSURLRequestReloadIgnoringCacheData

Since the config parameter in the constructor is currently not used for anything, is there other way i can change http cache policy for iOS?

Why is the cache being disabled on the iOS Client? Can it lead to problems?

Thanks in advance

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Stexxecommented, Feb 5, 2021

With the HttpCache feature installed it works as expected on iOS:

GlobalScope.launch(Dispatchers.Main) {
    val client = HttpClient(Ios) {
        install(HttpCache)
    }

    client.get<HttpResponse>("https://httpbin.org/cache")
    client.get<HttpResponse>("https://httpbin.org/cache")
}

The sample project is attached ios_cache.zip

If you have a case where caching doesn’t work as expected please describe it in the relevant YouTrack issue.

1reaction
e5lcommented, Mar 4, 2019

Hi @jrocharodrigues, thanks for the report.

We try to unify the client behavior with each engine. So we set HttpCache disabled by default. Probably we should expose request configuration in engine config.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Caching - Ktor
The Ktor client provides the HttpCache plugin that allows you to save previously fetched resources in an in-memory or persistent cache.
Read more >
Persistent Client HttpCache : KTOR-2579 - YouTrack
Currently the HttpCache is implemented as in-memory only. Accordingly using it in an iOS/Android multiplatform app, cache entries are lost when closing the ......
Read more >
Ktor force refresh cache-control endpoint - Stack Overflow
I've started using Ktor (recently updated to 2.0.0) on a new android project, ... val client = HttpClient(CIO) { install(HttpCache) }.
Read more >
Increasing Application Performance with HTTP Cache Headers
HTTP caching is a universally adopted specification across all modern web browsers, making its implementation in web applications simple.
Read more >
How to Make HTTP Requests With Ktor-Client in Android
Ktor is a client-server framework that helps us build applications in Kotlin. It is a modern asynchronous framework backed by Kotlin ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found