CacheSource增加getDel方法

This commit is contained in:
redkale
2023-07-15 22:06:51 +08:00
parent f9463c0f82
commit 222969e8a3
2 changed files with 32 additions and 0 deletions

View File

@@ -661,6 +661,13 @@ public final class CacheMemorySource extends AbstractCacheSource {
}, getExecutor());
}
@Override
public <T> CompletableFuture<T> getDelAsync(String key, Type type) {
return supplyAsync(() -> {
return (T) container.remove(key);
}, getExecutor());
}
protected void set(CacheEntryType cacheType, int expireSeconds, String key, Object value) {
if (key == null) {
return;

View File

@@ -205,6 +205,20 @@ public interface CacheSource extends Resourcable {
return val == null ? defValue : val;
}
//------------------------ getdel ------------------------
default <T> T getDel(String key, Type type) {
return (T) getDelAsync(key, type).join();
}
default String getDelString(String key) {
return getDel(key, String.class);
}
default long getDelLong(String key, long defValue) {
Long val = getDel(key, Long.class);
return val == null ? defValue : val;
}
//------------------------ 键 Keys ------------------------
default long del(String... keys) {
return delAsync(keys).join();
@@ -1049,6 +1063,17 @@ public interface CacheSource extends Resourcable {
return getSetAsync(key, Long.class, value).thenApply(v -> v == null ? defValue : (Long) v);
}
//------------------------ getdel ------------------------
public <T> CompletableFuture<T> getDelAsync(String key, Type type);
default CompletableFuture<String> getDelStringAsync(String key) {
return getDelAsync(key, String.class);
}
default CompletableFuture<Long> getDelLongAsync(String key, long defValue) {
return getDelAsync(key, Long.class).thenApply(v -> v == null ? defValue : (Long) v);
}
//------------------------ 键 Keys ------------------------
public CompletableFuture<Long> delAsync(String... keys);