Hey guys, I have a question. Is there a way in Kto...
# ktor
j
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
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
That's what I'm trying to achieve, is there any built-in kotr functionality for this?
t
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
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
Oh, you are looking for a cache for
HttpClient
? There is one, in the form of the
HttpCache
feature.
j
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