Skip to content

Commit d956c78

Browse files
committed
📝 redis 组件添加批量清除缓存文档,修正文档缓存示例中@cached ttl属性示例类型中使用错误的问题,long类型的ttl不需要双引号
1 parent 67d9609 commit d956c78

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

docs/guide/feature/redis.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ keyJoint 的值为 [SPEL 表达式](https://docs.spring.io/spring-framework/docs
174174
注解示例:
175175

176176
```java
177-
@Cached(key = "testKey", keyJoint = "#p0", ttl="86400")
177+
@Cached(key = "testKey", keyJoint = "#p0", ttl=86400)
178178
public User getUser(String userName) {
179179
return new User("zhangsan", 18);
180180
}
@@ -228,6 +228,14 @@ public @interface CacheDel {
228228
* @return boolean
229229
*/
230230
boolean multiDel() default false;
231+
232+
233+
/**
234+
* 是否删除缓存空间key下的所有条目
235+
* 默认情况下,只删除相关键下的值。
236+
* 注意,设置该参数为true时,指定的 keyJoint与multiDel将被忽略.
237+
*/
238+
boolean allEntries() default false;
231239
}
232240
```
233241

@@ -257,6 +265,17 @@ public User updateUserStatus(List<String> usernameList, String status) {
257265
}
258266
```
259267

268+
有的时候我们需要一下清除Cache中所有的元素,因此类似于Spring Cache项目的@CacheEvict,```@CacheDel```同样提供了```allEntries```属性。```allEntries```是boolean类型,表示是否需要清除缓存中的所有元素。默认为false,表示不需要。当指定了```allEntries```为true时,将忽略指定的keyJoint表达式,通过redis scan删除```@CacheDel``````key```属性能命中的所有相关的缓存。
269+
270+
清除缓存示例:
271+
272+
```java
273+
@CacheDel(key = "testKey", allEntries = true)
274+
public User removeUser(String username) {
275+
return mapper.removeUser(username);
276+
}
277+
```
278+
260279
进阶玩法,集合投影,可以对集合的元素操作,获取新的集合数据,类似于 stream 的 map 方法:
261280

262281
```java

0 commit comments

Comments
 (0)