doc
This commit is contained in:
@@ -4,20 +4,21 @@
|
|||||||
     2、返回类型必须是可json序列化的 <br>
|
     2、返回类型必须是可json序列化的 <br>
|
||||||
     3、修饰必须是```protected```/```public``` <br>
|
     3、修饰必须是```protected```/```public``` <br>
|
||||||
     4、修饰不能是```final```/```static``` <br>
|
     4、修饰不能是```final```/```static``` <br>
|
||||||
|
  本地缓存和远程缓存可同时设置,```expire```设置为0,表示永不过期。
|
||||||
|
|
||||||
  将结果进行本地缓存30秒
|
  将结果进行本地缓存30秒且远程缓存60秒
|
||||||
```java
|
```java
|
||||||
@Cached(key = "name", localExpire = "30")
|
@Cached(key = "name", localExpire = "30", remoteExpire = "60")
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "haha";
|
return "haha";
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
  以参数code为key将结果进行本地缓存(时长由环境变量```env.cache.expire```配置,没有配置采用默认值30秒)、远程缓存60秒
|
  以参数code为key将结果进行本地缓存(时长由环境变量```env.cache.expire```配置,没配置采用默认值30秒)
|
||||||
```java
|
```java
|
||||||
@Cached(key = "#{code}", localExpire = "${env.cache.expire:30}", remoteExpire = "60")
|
@Cached(key = "#{code}", localExpire = "${env.cache.expire:30}")
|
||||||
public CompletableFuture<String> getNameAsync(String code) {
|
public CompletableFuture<String> getNameAsync(String code) {
|
||||||
return CompletableFuture.completedFuture(code);
|
return redis.getStringAsync(code);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1,36 @@
|
|||||||
文档完善中……
|
# 定时任务
|
||||||
|
  @Scheduled注解在Service的方法上,实现对方法结果进行定时运行。方法必须是无参数或者```ScheduleEvent```参数。
|
||||||
|
|
||||||
|
  每秒执行
|
||||||
|
```java
|
||||||
|
@Scheduled(cron = "0/1 * * * * ?")
|
||||||
|
public void task1() {
|
||||||
|
System.out.println(Times.nowMillis() + "执行一次");
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
  <b>环境配置</b>, 定时间隔时间由环境变量```env.schedule.fixedRate```配置,没配置采用默认值60秒)
|
||||||
|
```java
|
||||||
|
@Scheduled(fixedRate = "${env.schedule.fixedRate:60}")
|
||||||
|
public String task2() {
|
||||||
|
System.out.println(Times.nowMillis() + "执行一次");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
  <b>支持乘法表达式</b>, 系统启动后延迟10分钟后每60分钟执行一次,
|
||||||
|
```java
|
||||||
|
@Scheduled(fixedDelay = "10", fixedRate = "2*30", timeUnit = TimeUnit.MINUTES)
|
||||||
|
private void task3() {
|
||||||
|
System.out.println(Times.nowMillis() + "执行一次");
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
# 定时配置
|
||||||
|
```xml
|
||||||
|
<!--
|
||||||
|
全局Serivce的定时任务设置,没配置该节点将自动创建一个。
|
||||||
|
enabled: 是否开启缓存功能。默认: true
|
||||||
|
-->
|
||||||
|
<schedule enabled="true"/>
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user