【发布时间】:2021-11-08 14:35:47
【问题描述】:
在我基于 Spring Boot 的 Java 应用中,我正在尝试为以下服务方法实现缓存机制:
@Override
public List<EmployeeDTO> findAllByCountry(Country country) {
final Map<Pair<UUID, String>, List<CountryTranslatable>> valueList
= countryRepository...
// code omitted for brevity
}
在关于这个问题的几个例子之后,我决定采用A Guide To Caching in Spring中提到的方法。
但是,我有点困惑,因为它包含 Spring 和 Spring Boot 实现并使用不同的注释示例。我想我应该从3.1开始。在使用 Spring Boot 时使用 Spring Boot 部分,但我不确定应该使用哪个缓存注释(4.1。@Cacheable 似乎没问题,但我不确定)。
那么,我应该把SimpleCacheCustomizer 放在哪里,如何将这种方法应用于我上面的服务方法(findAllByCountry)?任何简单的例子都会非常感激,因为我是 Spring 的新手。
【问题讨论】:
标签: java spring spring-boot caching