默认使用proxy模式,即cacheable方法,只能通过外部接口调用才会生效,
如果要支持class内自已调用,请使用ASPECTJ
模式
@EnableCaching
public class AppConfig {
@Bean
public CacheManager cacheManager() {
return new GuavaCacheManager("history", "total", "case_tracking", "global_tracking");
}
}
@Cacheable(value = "total", key = "#type.value+#date")
public long getTotalCountsBefore(ReportType type, LocalDate date) {
}
@CacheEvict(value = "total", key = "#type.value+#date")
public void saveTotalHistoryData(ReportType type, LocalDate date, Long count) {
}