We have a Java web backend service running on 2 production servers with 2 JVMs in each of them, behind a load balancer in Websphere Application Server.
My Use Case:
- Call an external API first time after deployment.
- If Response.OK
- Cache the response in an external datastore (not relevant for this question)
- For the next client requests of the day and if the time of the requests are not equal to or immediately after a set of times (9:00, 11:00, 13:00, 15:00)
- Return the cached response
- If the client request happens to be on any given time in the set (9:00, 11:00, 13:00, 15:00)
- Call the external API and update cache (not relevant again). Example., request comes at 9:00
- For all the subsequent requests from 9:00 to 10:59 (because next time in the set is 11:00)
- Return the cached response
- At 11:00
- Call the external API and update cache
- And so on..
This way there are only four requests to the external API in a day as opposed to directly calling the external API for every request.
How can I achieve this at the application level in Java across all the production servers, accounting for the daylight saving time in a particular timezone, without any network or IO programming?
Note: The application does not use Spring boot. I'm trying to do this purely in Java.