Application cache

Now that our web requests have been compressed and cached, the next step we can take to reduce server load is to put the results of costly operations in a cache. The Twitter search takes some time and will consume our application request ratio on the Twitter API. With Spring, we can easily cache the search and return the same result each time the search is called with the same parameters.

The first thing that we need to do is activate Spring caching with the @EnableCache annotation. We also need to create a CacheManager that will resolve our caches. Let's create a CacheConfiguration class in the config package:

package masterSpringMvc.config; import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.EnableCaching; ...

Get Spring MVC: Designing Real-World Web Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.