作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个存储库类,如下所示:
@EnableCaching
@EnableScheduling
@Repository("dao")
public class CustomerDao implements CustomerDao<Customer> {
//...
@Cacheable(value = "customers")
@Override
public List<Customer> getAll() {
LOG.info("in getALL() method");
return this.jdbcTemplate.query(this.QUERY_ALL_CUSTOMER, new CustomerRowMapper());
}
@CacheEvict(value = "customers", allEntries = true)
@Scheduled(fixedDelay = 60000L)
public void refreshAllCustomers() {
LOG.info("Refreshing Customers");
getAll();
LOG.info("Refreshing Customers Finished");
}
}
当我第一次调用调用 getAll()
的 api 时,它按照预期需要时间。当我再次调用 getAll()
时,速度很快,因为结果按预期从缓存中返回。
但是,按照计划,我调用 refreshAllCustomers()
来清除缓存并使用 getAll()
调用重新填充缓存,在这种情况下,我希望结果为再次被缓存。
在调用 refreshAllCustomers()
后,似乎对 getAll()
的任何调用都会运行查询,并且不会从缓存本身返回结果。
有什么想法为什么会发生这种情况吗?我是否缺少配置或没有正确执行某些操作。
最佳答案
@CacheEvict
方法执行后生效。refreshAllCustomers()
方法执行后,缓存被清除。如果要使用@CacheEvict
注解可以在方法执行前使缓存失效,可以尝试@CacheEvict(value =customers, before Invocation = true)
关于java - 按计划进行缓存驱逐后,Spring 缓存未被使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57673771/
我需要部署一个混合了纯 PHP、JavaScript、jQuery 和 AJAX 的应用程序。当在浏览器中调用时,它可以在所有计算机上完美运行。不幸的是,我还需要将此应用程序部署到无法运行浏览器的计算
我是一名优秀的程序员,十分优秀!