https://kotlinlang.org logo
#ktor
Title
# ktor
j

Jan Stoltman

07/11/2019, 8:23 AM
Hey guys, I have a question. Is there a way in Ktor to limit identical GET requests to the same endpoint from the client's side? Eg. if my client app makes a single GET request to the
xyz
endpoint and then at almost the same time makes another two to the same endpoint with the same method/payload, I would like to let only the first one to actually reach the server and deliver response to all 3 client requests. Is there any way to achieve this with ktor?
t

tseisel

07/11/2019, 9:17 AM
If all requests are the same, you should implement an HTTP caching strategy, so that the same response is sent to all clients while calculating it only once
j

Jan Stoltman

07/11/2019, 9:24 AM
That's what I'm trying to achieve, is there any built-in kotr functionality for this?
t

tseisel

07/11/2019, 9:55 AM
Have a look at this : https://ktor.io/servers/features/caching-headers.html I haven't used it yet, but it seems to be what you are looking for. You could also store data required to generate the response in a
Map
, reading from it if the request is the same.
j

Jan Stoltman

07/11/2019, 10:01 AM
Caching-headers are all about server or proxy side cache afaik, no mention of client side. I guess I will have to implement it on my own, thank you for help 🙂
t

tseisel

07/11/2019, 10:04 AM
Oh, you are looking for a cache for
HttpClient
? There is one, in the form of the
HttpCache
feature.
j

Jan Stoltman

07/11/2019, 10:08 AM
What I'm really looking for is the limitation of multiple requests with the same method/url/payload to one endpoint
So only one of these requests would fly and fetch data and then pass the result to the rest
3 Views