From 0c10e928fcdc49dfd6485c5fc2fc054caff8502a Mon Sep 17 00:00:00 2001 From: redkale Date: Tue, 26 Dec 2023 15:04:41 +0800 Subject: [PATCH] doc --- docs/cached.md | 11 ++++++----- docs/scheduled.md | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/docs/cached.md b/docs/cached.md index 7b98fe49e..50626eb49 100644 --- a/docs/cached.md +++ b/docs/cached.md @@ -4,20 +4,21 @@      2、返回类型必须是可json序列化的
     3、修饰必须是```protected```/```public```
     4、修饰不能是```final```/```static```
+  本地缓存和远程缓存可同时设置,```expire```设置为0,表示永不过期。 -  将结果进行本地缓存30秒 +  将结果进行本地缓存30秒且远程缓存60秒 ```java - @Cached(key = "name", localExpire = "30") + @Cached(key = "name", localExpire = "30", remoteExpire = "60") public String getName() { return "haha"; } ``` -  以参数code为key将结果进行本地缓存(时长由环境变量```env.cache.expire```配置,没有配置采用默认值30秒)、远程缓存60秒 +  以参数code为key将结果进行本地缓存(时长由环境变量```env.cache.expire```配置,没配置采用默认值30秒) ```java - @Cached(key = "#{code}", localExpire = "${env.cache.expire:30}", remoteExpire = "60") + @Cached(key = "#{code}", localExpire = "${env.cache.expire:30}") public CompletableFuture getNameAsync(String code) { - return CompletableFuture.completedFuture(code); + return redis.getStringAsync(code); } ``` diff --git a/docs/scheduled.md b/docs/scheduled.md index f1c8470a4..61e4bdbc7 100644 --- a/docs/scheduled.md +++ b/docs/scheduled.md @@ -1 +1,36 @@ -文档完善中…… \ No newline at end of file +# 定时任务 +  @Scheduled注解在Service的方法上,实现对方法结果进行定时运行。方法必须是无参数或者```ScheduleEvent```参数。 + +  每秒执行 +```java + @Scheduled(cron = "0/1 * * * * ?") + public void task1() { + System.out.println(Times.nowMillis() + "执行一次"); + } +``` + +  环境配置, 定时间隔时间由环境变量```env.schedule.fixedRate```配置,没配置采用默认值60秒) +```java + @Scheduled(fixedRate = "${env.schedule.fixedRate:60}") + public String task2() { + System.out.println(Times.nowMillis() + "执行一次"); + return ""; + } +``` + +  支持乘法表达式, 系统启动后延迟10分钟后每60分钟执行一次, +```java + @Scheduled(fixedDelay = "10", fixedRate = "2*30", timeUnit = TimeUnit.MINUTES) + private void task3() { + System.out.println(Times.nowMillis() + "执行一次"); + } +``` + +# 定时配置 +```xml + + +``` \ No newline at end of file