diff --git a/core/src/main/java/com/safframework/rxcache/CacheRepository.java b/core/src/main/java/com/safframework/rxcache/CacheRepository.java index 9a3f174..fb0e143 100644 --- a/core/src/main/java/com/safframework/rxcache/CacheRepository.java +++ b/core/src/main/java/com/safframework/rxcache/CacheRepository.java @@ -316,7 +316,7 @@ protected boolean containsKey(String key) { } } - protected boolean checkKey(String key) { + protected boolean checkKey(String key) throws RxCacheException { try { return getStringData(key)!=null; } catch (Exception e){ diff --git a/core/src/main/java/com/safframework/rxcache/RxCache.java b/core/src/main/java/com/safframework/rxcache/RxCache.java index f572232..cb203e4 100644 --- a/core/src/main/java/com/safframework/rxcache/RxCache.java +++ b/core/src/main/java/com/safframework/rxcache/RxCache.java @@ -279,6 +279,7 @@ public boolean containsKey(String key) { /** * 校验 RxCache 是否可以获取这个 key * @param key + * @throws RxCacheException * @return */ public boolean checkKey(String key) throws RxCacheException { diff --git a/example/src/main/java/persistence/TestCheckKey.java b/example/src/main/java/persistence/TestCheckKey.java index f3ba1c9..3997a01 100644 --- a/example/src/main/java/persistence/TestCheckKey.java +++ b/example/src/main/java/persistence/TestCheckKey.java @@ -1,6 +1,7 @@ package persistence; import com.safframework.rxcache.RxCache; +import com.safframework.rxcache.exception.RxCacheException; import com.safframework.rxcache.persistence.disk.impl.DiskImpl; import java.io.File; @@ -27,11 +28,15 @@ public static void main(String[] args) { RxCache.config(new RxCache.Builder().persistence(diskImpl)); RxCache rxCache = RxCache.getRxCache(); - Boolean result = rxCache.checkKey("test"); - System.out.println(result); + try { + Boolean result = rxCache.checkKey("test"); + System.out.println(result); + + if (!result) { + rxCache.remove("test"); + } + } catch (RxCacheException e) { - if (!result) { - rxCache.remove("test"); } } }