We just talked about safeguarding RestTemplate HTTP Operations from spitting out exceptions when the API Endpoint is not available. Now we're going to speed up processing a RestTemplate HTTP Get object with Spring Caching.
We're using EhCache 3 as our Spring Cache Provider so we begin by adding a githubStats Cache in our ehcache3.xml file. (For Spring Caching configuration details see this NixMash Post.)
Now we'll cache the method which retrieves our GitHub Project statistics.
What's interesting in the above @Cacheable annotation is using the method name as our Cache Key. Let's show that key in action. Notice the githubCache.get(“getGitHubStats”).get() statement below.
Okay, now for the payoff. Let's look at the performance improvements of caching our RestTemplate GET object data. Awesome sauce!