Reputation: 41
Hi i am trying to set up caching for my ktor server. It also uses ktor client to make requests to some urls to fetch json files. I wanted to use In-Memory caching for the client but it does not seem to work. When i make a request it tells me that it is caching the response for the url. However follow up requests are not faster because it always outputs
"Cached response is stale for ... should validate cached response".
My HttpClient i use for making requests currently looks like this:
object HttpClient {
val client = HttpClient(CIO) {
install(ContentNegotiation) {
json(Json {
prettyPrint = true
isLenient = true
ignoreUnknownKeys = true
})
}
install(HttpCache)
install(HttpTimeout)
install(Logging) {
logger = Logger.DEFAULT
level = LogLevel.HEADERS
sanitizeHeader { header -> header == HttpHeaders.Authorization }
}
}
}
and then i just make requests like this:
val response: List<myDataClass> = client.get(someUrl).body()
I also tried persistent caching. It actually stores something in the folder i defined but again, follow up requests are always stale no matter what
Upvotes: 3
Views: 744