How it works...

Spring 5.0 supports several cache implementations such as Gemfire, Guava Cache, and Ehcache. Since Ehcache is the most widely used type, this recipe injected org.springframework.cache.ehcache.EhCacheCacheManager to implement the CacheManager abstraction and instantiated org.springframework.cache.ehcache.EhCacheManagerFactoryBean to generate net.sf.ehcache.Cache into the diskStore. One of the caches named employeesCache is being utilized by the CacheListenerAspect, which intercepts the getEmployees() of the EmployeeDaoImpl class. This aspect class has an @Around advice named cacheMonitor() that caches always the first batch of List<Employees> data returned by getEmployees() in order to prevent the method from accessing the database again the next time it is executed by the application.

Although this solution is quite helpful and flexible, some developers still use @EnableCaching, the built-in Spring cache, to use Spring's popular annotations such as @Cacheable and @CacheEvict.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.253.223