File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed
Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -99,12 +99,29 @@ public interface UserMapper {
9999
100100使用Magic模式后,如果上面ids有10条记录,最差情况需要访问1次缓存、1数据源以及1次写缓存操作;最好的情况只需要访问1次缓存。但使用Magic模式后,就不允许使用自动加载(autoload设置为true也不会生效)、不支持“拿来主义”、异步刷新等功能。
101101
102+ 从7.0.4版本开始Magic模式也可用于无参函数,但此时只能从数据源加载数据,并批量写入缓存。
103+
102104有时我们也需要动态精确批量删除缓存,比如更新一批商品信息后,也要批量删除缓存,在7.0.1版本之前需要在业务代码中使用循环操作来实现。
103105
104- 7.0.3版本在 @ CacheDeleteKey 增加 iterableArgIndex 属性,当它大于等于0时开启Magic模式。
106+ 7.0.4版本中增加 @ CacheDeleteMagicKey 用于开启Magic模式,并支持对参数或返回值进行分割,然后生成多个Cache key进行批量删除缓存。如下例子所示:
105107
106108``` java
107- @CacheDelete (@CacheDeleteKey (value = " 'user-byid-' + #args[0]" , iterableArgIndex = 0 ))
108- void deleteByIds(@Param (" ids" ) List<Long > ids);
109+ @CacheDelete (magic = {
110+ @CacheDeleteMagicKey (value = " 'user-testMagic-' + #args[0] + '-' + #args[1] + '-' + #args[2]" , iterableArgIndex = 2 , iterableReturnValue = false )
111+ })
112+ public void testDeleteMagicForArg(String name, String password, Long . .. ids) {
113+
114+ }
115+
116+ @CacheDelete (magic = {
117+ @CacheDeleteMagicKey (value = " 'user-testMagic-' + #args[0] + '-' + #args[1] + '-' + #retVal.id" , iterableArgIndex = - 1 , iterableReturnValue = true )
118+ })
119+ public List<UserDO > testDeleteMagicForRetVal(String name, String password, Long . .. ids) {
120+ List<UserDO > list = new ArrayList<> (ids. length);
121+ for (Long id : ids) {
122+ list. add(new UserDO (id, name, password));
123+ }
124+ return list;
125+ }
109126```
110127
You can’t perform that action at this time.
0 commit comments