To enable caching, Spring makes good use of annotations, much like enabling any other configuration level feature in the framework.
The caching feature can be enabled by simply providing a cache setup component.
@SpringBootApplication
@EnableCaching
public class MyApplication
@Component
public class CachingSetup implements JCacheManagerCustomizer
{
@Override
public void customize(CacheManager cacheManager)
{
cacheManager.createCache("my_cache", new MutableConfiguration<>()
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(SECONDS, 10000)))
.setStoreByValue(true)
.setStatisticsEnabled(true));
}
}