Skip to content
This repository was archived by the owner on Nov 21, 2020. It is now read-only.

Commit 6b40972

Browse files
committed
feat: add cache del method
1 parent d9a5878 commit 6b40972

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Boot Surface主要是一个依赖于Spring框架的Web开发工具类,旨在
2727
<dependency>
2828
<groupId>org.code4everything</groupId>
2929
<artifactId>boot-surface</artifactId>
30-
<version>1.1.4</version>
30+
<version>1.1.5</version>
3131
</dependency>
3232
```
3333

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<groupId>org.code4everything</groupId>
1414
<artifactId>boot-surface</artifactId>
15-
<version>1.1.4</version>
15+
<version>1.1.5</version>
1616
<packaging>jar</packaging>
1717

1818
<name>boot-surface</name>

src/main/java/org/code4everything/boot/cache/BootCacheManager.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import cn.hutool.core.collection.ConcurrentHashSet;
55
import cn.hutool.core.util.ObjectUtil;
66
import cn.hutool.core.util.StrUtil;
7+
import org.code4everything.boot.base.bean.BaseDomain;
78
import org.code4everything.boot.base.constant.StringConsts;
89
import org.springframework.cache.Cache;
910
import org.springframework.cache.CacheManager;
@@ -188,6 +189,50 @@ public <T> void delVal(String cacheName, String key, CacheRemovable<T> removable
188189
collection.removeIf(removable::shouldRemove);
189190
}
190191

192+
/**
193+
* 从缓存列表中移除缓存
194+
*
195+
* @param cacheName 缓存名称
196+
* @param key 键
197+
* @param value 需要从列表中移除的值
198+
* @param <T> 值类型
199+
*
200+
* @since 1.1.5
201+
*/
202+
public <T> void delVal(String cacheName, String key, T value) {
203+
Collection<T> collection = getValByType(cacheName, key);
204+
if (CollUtil.isEmpty(collection)) {
205+
return;
206+
}
207+
collection.removeIf(t -> Objects.equals(t, value));
208+
}
209+
210+
/**
211+
* 从缓存列表中移除缓存
212+
*
213+
* @param cacheName 缓存名称
214+
* @param key 键
215+
* @param value 需要从列表中移除的值
216+
* @param <T> 值类型
217+
*
218+
* @since 1.1.5
219+
*/
220+
public <T extends BaseDomain> void delDomain(String cacheName, String key, T value) {
221+
Collection<T> collection = getValByType(cacheName, key);
222+
if (CollUtil.isEmpty(collection)) {
223+
return;
224+
}
225+
collection.removeIf(t -> {
226+
if (t == value) {
227+
return true;
228+
} else if (Objects.isNull(t) || Objects.isNull(value)) {
229+
return false;
230+
} else {
231+
return t.primaryKey().equals(value.primaryKey());
232+
}
233+
});
234+
}
235+
191236
/**
192237
* 删除所有对象缓存,works on all caches if cacheName==null || cacheName=="" || cacheName=="*"
193238
*

0 commit comments

Comments
 (0)