1.Spring缓存支持
Spring定义了org.springframework.cache.CacheManager和org.springframework.cache.Cache接口用来统一不同的缓存的技术。其中,CacheManager是Spring提供的各种缓存技术抽象接口
使用方法:
@Bean
public EhCacheCacheManager cacheManager(CacheManager ehCacheCacheManager) {
return new EhCacheCacheManager(ehCacheCacheManager);
}
2.声名式缓存注解
@Cacheable、@CachePut、@CacheEvit都有value属性,指定的是要使用的缓存名称;key属性指定的是
数据在缓存中的存储的键。
3.开启声名式缓存支持
开启声名式缓存支持十分简单,只需在配置类上使用@EnableCaching注解即可
@Configuration
@EnableCaching
public class AppConfig {
}
public interface UserInfoDao extends JpaRepository<UserInfo, Long> {
}
@Service
public class UserInfoServiceImpl implements UserInfoService {
private static Logger log = Logger.getLogger(String.valueOf