Databases Reference
In-Depth Information
We can add caching support to our example application by following these steps:
1. Configure the Spring cache abstraction.
2.
Identify the cached methods.
We will also learn how we can verify that the Spring cache abstraction is
working correctly.
Configuring the Spring cache abstraction
We can configure the Spring cache abstraction by making the following changes to
the application context configuration of our application:
1. Enable the caching annotations.
2. Configure the host and port of the used Redis instance in the used
properties file.
3. Configure the Redis connection factory bean.
4. Configure the Redis template bean.
5. Configure the cache manager bean.
Enabling caching annotations
We can enable the caching annotations by annotating our application context
configuration class with the @EnableCaching annotation. The relevant part of the
ApplicationContext class is given as follows:
@Configuration
@ComponentScan(basePackages = {
"com.packtpub.springdata.jpa.controller",
"com.packtpub.springdata.jpa.service"
})
@EnableCaching
@EnableTransactionManagement
@EnableWebMvc
@EnableJpaRepositories("com.packtpub.springdata.jpa.repository")
@PropertySource("classpath:application.properties")
public class ApplicationContext extends WebMvcConfigurerAdapter {
@Resource
private Environment env;
//Bean declarations
}
 
Search WWH ::




Custom Search