This repository was archived by the owner on Nov 21, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +73
-13
lines changed Expand file tree Collapse file tree 5 files changed +73
-13
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,8 @@ Boot Surface主要是一个依赖于Spring框架的Web开发工具类,旨在
55
55
56
56
- [ 消息类] ( docs/message.md )
57
57
58
+ - [ Spring注解缓存] ( docs/cache.md )
59
+
58
60
## 示例项目
59
61
60
62
[ https://gitee.com/code4everything/wanna-spring/tree/master/spring-bee ] ( https://gitee.com/code4everything/wanna-spring/tree/master/spring-bee )
Original file line number Diff line number Diff line change
1
+ ## Spring注解缓存
2
+
3
+ 本模块简单的实现了 ` Google Guava Cache ` 和 ` Redis ` 的 ` Spring ` 缓存版,还没有使用过 ` Spring Cache ` 的小伙伴,可以自行谷歌了解下
4
+
5
+
6
+ #### 创建缓存管理器
7
+
8
+ ``` java
9
+ @Bean
10
+ public GuavaCacheManager guavaCacheManager() {
11
+ // @formatter:off
12
+ CacheBuilder<Object , Object > cacheBuilder = CacheBuilder . newBuilder()
13
+ .expireAfterWrite(30 , TimeUnit . MINUTES )
14
+ .softValues()
15
+ .initialCapacity(128 )
16
+ .maximumSize(1024 );
17
+ // @formatter:on
18
+ return CacheUtils . newGuavaCacheManager(cacheBuilder, " cache1" , " cache2" );
19
+ }
20
+ ```
21
+
22
+ ``` java
23
+ @Bean
24
+ public RedisCacheManager redisCacheManager() {
25
+ Map<String , RedisCacheCreator > creatorMap = new HashMap<> (2 , 1 );
26
+ // 不同的缓存使用不同的缓存策略
27
+ creatorMap. put(" cache1" , new RedisCacheCreator (60 * 60 ));
28
+ creatorMap. put(" cache2" , new RedisCacheCreator (60 * 60 * 24 ));
29
+ return CacheUtils . newRedisCacheManager(creatorMap);
30
+ }
31
+ ```
32
+
33
+ 提供多种创建方式,你可以选择任意你喜欢的方式创建
34
+
35
+ #### 开启缓存
36
+
37
+ ``` java
38
+ @EnableCaching
39
+ ```
40
+
41
+ #### 使用注解缓存
42
+
43
+ ``` java
44
+ @Cacheable (value = " cache1" , key = " #root.method" , cacheManager = " guavaCacheManager" )
45
+ ```
46
+
47
+ 或者
48
+
49
+ ``` java
50
+ @Cacheable (value = " cache2" , key = " #root.args" , cacheManager = " redisCacheManager" )
51
+ ```
52
+
53
+ 当然,你也可以不使用注解,直接在代码中手动缓存,使用你用到的 ` CacheManager ` 即可
Original file line number Diff line number Diff line change @@ -93,3 +93,9 @@ setFieldEncoder(org.code4everything.boot.base.encoder.DefaultFieldEncoder)
93
93
```
94
94
95
95
> [ 用法参考] ( response.md )
96
+
97
+ > [ PROPERTY配置样本] ( ../src/main/resources/application-sample.properties )
98
+
99
+ > [ JSON配置样本] ( ../src/main/resources/boot-config-sample.json )
100
+
101
+ > [ LOGBACK日志配置样本] ( ../src/main/resources/logback-sample.xml )
Original file line number Diff line number Diff line change 42
42
43
43
如果是通过邮件发送验证码,那么你需要先配置邮箱,请参考上面的说明
44
44
45
- > 目前仅支持邮箱发送验证码,短信验证码后期会完善的
46
-
47
- - 发送验证码
45
+ - 邮箱发送验证码
48
46
49
47
``` java
50
48
// 验证码有效期:30分钟
51
49
VerifyCodeUtils.sendByMailAsync("sendto@example.com", "验证码", "你的验证码:{},请不要告诉其他人哦");
52
50
```
53
51
52
+ - 短信(包括任何其他方式)的验证码发送
53
+
54
+ 需要一个实现了 `MessageSender` 的类,在类中你可以定义任何消息的发送
55
+
56
+ ``` java
57
+ // 你需要实现的类
58
+ MessageSender sender = new MessageSender();
59
+ VerifyCodeUtils.sendBy(sender, "18780692121", "你的验证码:{},请不要告诉其他人哦");
60
+ ```
61
+
54
62
- 校验验证码
55
63
56
64
``` java
Original file line number Diff line number Diff line change 12
12
13
13
<groupId >org.code4everything</groupId >
14
14
<artifactId >boot-surface</artifactId >
15
- <version >1.1.3 </version >
15
+ <version >1.1.4 </version >
16
16
<packaging >jar</packaging >
17
17
18
18
<name >boot-surface</name >
19
19
<url >https://github.com/code4everything/boot-surface</url >
20
20
21
- <!-- private nexus maven snapshot repository, removing this when deploy to maven centre repository-->
22
- <distributionManagement >
23
- <repository >
24
- <id >maven-snapshots</id >
25
- <name >Nexus Snapshot Repository</name >
26
- <url >http://nexus.code4everything.org/repository/maven-snapshots/</url >
27
- </repository >
28
- </distributionManagement >
29
-
30
21
<properties >
31
22
<project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
32
23
<maven .compiler.source>1.8</maven .compiler.source>
You can’t perform that action at this time.
0 commit comments