java - 将@Scheduled 应用于@Cacheable 休息方法
问题描述
我正在尝试将计划添加到 rest get 方法,当我在没有 @Cacheable 注释的情况下使用它时,计划程序可以正常工作。像这样——
@Scheduled(fixedDelay = 1000*5)
@GetMapping("test")
public void test(){
System.out.println("scheduled task through spring");
}
问题是,当我添加@Cacheable 注解时,请求被加载一次,然后调度程序不会重复。
@Scheduled(fixedDelay = 1000*5)
@Cacheable("testData")
@GetMapping("test")
public void test(){
System.out.println("scheduled task through spring");
}
我用谷歌搜索过,但我只能用@Scheduled 找到关于@CacheEvict 的信息
解决方案
我不相信@Cacheable
采用一种void
方法是有意义的。即使该方法正在返回一个值...
我相信@Scheduled
正在触发,但@Cacheable
会导致返回缓存值,而不是再次执行该方法。我认为这是有道理的。
打开 DEBUG 日志记录以进行验证。
祝你好运!
推荐阅读
- node.js - 如何实现一个节点 js 查询,该查询应该显示来自两个不同表的特定模型的数据?我正在使用环回框架
- android - Android 9 ResolvableApiException onActivityResult 有 resultCode 0 RESULT_CANCELED
- angularjs - 任何改变路线的方法|| angularJS中的指令状态?
- oracle - Oracle 12.2 中的标识符太长问题
- android - 将可绘制对象设置为背景以查看返回未找到可绘制对象
- javascript - JavaScript 严重错误 - SCRIPT1004:应为“;”
- python - 使用 Python 正则表达式提取 javascript 变量
- javascript - 如何在本机反应中设置固定菜单大小?
- javascript - 我将如何将 JSON 数据嵌入到我的 HTML 文件中?
- python - 如何在 Pyspark 中过滤到最大日期?