我正在使用 Spring Boot 并使用 Ehcache 进行缓存。到目前为止一切正常。但是现在我必须重新加载/刷新,所以我该怎么做才能使我的应用程序不会有任何停机时间。
我在 Spring Ehcache 中尝试了很多方法,但它没有用,否则必须编写调度程序并重新加载数据。
@Override
@Cacheable(value="partTypeCache", key="#partKey")
public List<PartType> loadPartType(String partKey) throws CustomException {
return productIdentityDao.loadPartType();
}
原文由 Shubuu 发布,翻译遵循 CC BY-SA 4.0 许可协议
显然关于你的问题的所有评论都是正确的。你 应该 使用 CacheEvict。我在这里找到了解决方案: https ://www.baeldung.com/spring-boot-evict-cache,它看起来像这样:
您所要做的就是创建名为例如 CacheService 的类,并创建将驱逐您拥有的所有缓存对象的方法。然后你注释该方法 @Scheduled 并输入你的间隔率。