com.netflix.hystrix.contrib.javanica.cache.annotation.CacheResult- I am bit confused about this @CacheResult annotation given by Hystrix-Javanica. Per documentation- it can cache the result for a HystrixCommand. In the following example, service is always executing the @HystrixCommand annotated method and don't understand why the @CacheResult didn't come into play.
Map<String, String> map = new HashMap<>();
@CacheResult(cacheKeyMethod="getCacheKey")
@HystrixCommand(fallbackMethod = "callStudentServiceAndGetData_Fallback", commandProperties= {
@HystrixProperty(name="requestCache.enabled" , value="true")
} )
public String callStudentServiceAndGetData(@CacheKey String schoolname) {
System.out.println("Getting School details for " + schoolname);
String response = restTemplate.exchange("http://localhost:8098/getStudentDetailsForSchool/{schoolname}",HttpMethod.GET, null, new ParameterizedTypeReference<String>() {}, schoolname).getBody();
map.put(schoolname, response);
return response;
}
public String getCacheKey (String key) {
return map.get(key);
}
private String callStudentServiceAndGetData_Fallback(String schoolname) {
return "Service down. "+ new Date();
}
I didn't find any useful example of Hystrix with Javanica annotation. Can you please have a look what I am missing here? TIA