Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
fengzhizi715 committed Oct 9, 2023
1 parent b22eb44 commit 982a1fd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/com/safframework/rxcache/RxCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ public boolean containsKey(String key) {
/**
* 校验 RxCache 是否可以获取这个 key
* @param key
* @throws RxCacheException
* @return
*/
public boolean checkKey(String key) throws RxCacheException {
Expand Down
13 changes: 9 additions & 4 deletions example/src/main/java/persistence/TestCheckKey.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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");
}
}
}

0 comments on commit 982a1fd

Please sign in to comment.