forked from alibaba/jetcache
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix concurrent problem of CacheResult
- Loading branch information
huangli
committed
Oct 2, 2021
1 parent
75e6700
commit 995e70a
Showing
3 changed files
with
13 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,8 @@ | |
* @author <a href="mailto:[email protected]">huangli</a> | ||
*/ | ||
public class CacheGetResult<V> extends CacheResult { | ||
private V value; | ||
private CacheValueHolder<V> holder; | ||
private volatile V value; | ||
private volatile CacheValueHolder<V> holder; | ||
|
||
public static final CacheGetResult NOT_EXISTS_WITHOUT_MSG = new CacheGetResult(CacheResultCode.NOT_EXISTS, null, null); | ||
public static final CacheGetResult EXPIRED_WITHOUT_MSG = new CacheGetResult(CacheResultCode.EXPIRED, null ,null); | ||
|
@@ -35,9 +35,9 @@ public V getValue() { | |
|
||
@Override | ||
protected void fetchResultSuccess(ResultData resultData) { | ||
super.fetchResultSuccess(resultData); | ||
holder = (CacheValueHolder<V>) resultData.getOriginData(); | ||
value = (V) unwrapValue(holder); | ||
super.fetchResultSuccess(resultData); | ||
} | ||
|
||
static Object unwrapValue(Object holder) { | ||
|
@@ -55,8 +55,8 @@ static Object unwrapValue(Object holder) { | |
|
||
@Override | ||
protected void fetchResultFail(Throwable e) { | ||
super.fetchResultFail(e); | ||
value = null; | ||
super.fetchResultFail(e); | ||
} | ||
|
||
protected CacheValueHolder<V> getHolder() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
* @author <a href="mailto:[email protected]">huangli</a> | ||
*/ | ||
public class MultiGetResult<K, V> extends CacheResult { | ||
private Map<K, CacheGetResult<V>> values; | ||
private volatile Map<K, CacheGetResult<V>> values; | ||
|
||
public MultiGetResult(CompletionStage<ResultData> future) { | ||
super(future); | ||
|
@@ -32,14 +32,14 @@ public Map<K, CacheGetResult<V>> getValues() { | |
|
||
@Override | ||
protected void fetchResultSuccess(ResultData resultData) { | ||
super.fetchResultSuccess(resultData); | ||
values = (Map<K, CacheGetResult<V>>) resultData.getOriginData(); | ||
super.fetchResultSuccess(resultData); | ||
} | ||
|
||
@Override | ||
protected void fetchResultFail(Throwable e) { | ||
super.fetchResultFail(e); | ||
values = null; | ||
super.fetchResultFail(e); | ||
} | ||
|
||
public Map<K, V> unwrapValues() { | ||
|