Replies: 1 comment 8 replies
-
|
I can't speak authoritatively for Play, but how to handle this is very different for individual-server vs clustered-with-shared-cache environments -- which one do you have? Mind, I'm not sure that a simple drop-in library for your problem exists. But the answer fundamentally depends on this question: it's much easier to solve for single-node than for distributed. |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
In my project I have a controller method that reads some data from cache and returns is out.
If value in cache expired it gets data from external service, caches it again and returns to client.
(Let’s assume that getting data from this service is quite long).
But when traffic is very high and many clients want data from cache when it expires all of them send “their” requests to external service simultaneously.
As far as I googled it is “Cache stampede” problem: https://en.wikipedia.org/wiki/Cache_stampede
What I want of course is to make only the first client request to send a request to an external service and all next make wait until the first request retrieved data from external service and put it cache. Only then the suspended client requests should be “woken up” to read from cache already populated.
Additionally, there should be some timeout to wait for the first request to get data.
Does the Play Framework have something built-in like this?
I’ve done some googling of course but I didn’t find positive results.
I’ve found for example: https://github.com/ben-manes/caffeine/wiki/Faq#bulk-loads
but I don’t know if it can be used in the Play Framework project.
Also did some searching by AI’s and got some solutions but none of them seem simple and I don’t know if it is thread safe, etc.
So, has Play Framework any recommended solution?
Beta Was this translation helpful? Give feedback.
All reactions