Skip to content

Commit

Permalink
Fix logic issue
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzhiguo committed Jun 23, 2024
1 parent 3f79291 commit cddf54a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ private Cache<K, V> getCache() {
*/
public void whenRemove(K key, V value, RemovalCause removalCause) {
if (log.isDebugEnabled()) {
log.debug("[RemoveCallback]Remove cache key:{}, value:{}, cause:{}, cacheName={}", key, value, removalCause, getName());
log.debug("[RemoveCallback]Remove cache key:{}, value:{}, cause:{}, cacheName={}",
key, value, removalCause, getName());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ private LoadingCache<K, V> getCache() {
*/
public void whenRemove(K key, V value, RemovalCause removalCause) {
if (log.isDebugEnabled()) {
log.debug("[RemoveCallback]Remove cache key:{}, value:{}, cause:{}, cacheName={}", key, value, removalCause, getName());
log.debug("[RemoveCallback]Remove cache key:{}, value:{}, cause:{}, cacheName={}",
key, value, removalCause, getName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,26 @@ public V getValueWithSyncValue(K key, Y syncValue) throws Exception {
return getValue(key);
}
synchronized (this) {
boolean needSync = false;
if (!effectiveCheck(key, syncValue)) {
needSync = true;
removeValue(key);
getSyncValueLocalCache().putValue(key, syncValue);
if (log.isInfoEnabled()) {
log.info("[缓存同步]数据同步Key不一致,已更新!Cache={}, Key={}, SyncValue={}", getName(), key, syncValue);
}
V value = null;
try {
value = getValue(key);
if (needSync) {
getSyncValueLocalCache().putValue(key, syncValue);
if (log.isInfoEnabled()) {
log.info("[缓存同步]数据同步Key不一致,已更新!Cache={}, Key={}, SyncValue={}",
getName(), key, syncValue);
}
}
} catch (Exception e) {
log.error("Error occurred when getValue, Cache={}, Key={}, SyncValue={}",
getName(), key, syncValue, e);
}
return getValue(key);
return value;
}
}
}
Expand Down

0 comments on commit cddf54a

Please sign in to comment.