I have a scenario with below use case:
- The function
someFunctionToGetValuetakes around 10 seconds to process. - api is called ~300 requests per second.
- The data of this api is same for all users.
- The data changes rarely.
To handle the throughput I have used static variables as cache which refreshes every 10 minutes.
import javax.ws.rs.PATH;
import com.google.inject.Singleton;
@Path("/home")
@Singleton
class MyResource {
private static String value; //this is actually a complex huge pojo
@Get
public Response getConfigData(){
boolean isMinsLapsed=Calender.getInstance().get(Calender.Minute)%10==0;
if(value==null || isMinsLapsed){
value=someFunctionToGetValue();
}
return value;
}
}
This code needs to be sent to production and wondering on the below points.
- Drawbacks of using static variables as cache in above scenario?
- Any better ways of API caching with eviction in place?