我想在Spring Boot1.5中使用@Cacheable注解,而不需要任何外部缓存提供程序。如何为simple提供程序案例设置TTL?
根据this question和其他在线资源,我可以使用Guava的CacheBuilder通过提供一个CacheConfiguration来设置过期时间。
然而,似乎芭乐缓存是deprecated by Spring。那么如果没有Guava,如何为一个简单的Spring缓存设置TTL呢?
发布于 2019-07-17 11:44:38
你可以试试
Ehcache
在pom.xml中添加依赖项
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>3.6.2</version>
</dependency> 实现缓存
@Service
public class NumberService {
// ...
@Cacheable(
value = "squareCache",
key = "#number",
condition = "#number>10")
public BigDecimal square(Long number) {
BigDecimal square = BigDecimal.valueOf(number)
.multiply(BigDecimal.valueOf(number));
log.info("square of {} is {}", number, square);
return square;
}
}https://stackoverflow.com/questions/57068176
复制相似问题