|
|
|
@ -58,6 +58,7 @@ public class RedissonLocalCachedMap<K, V> extends RedissonMap<K, V> implements R
|
|
|
|
|
private int invalidateEntryOnChange;
|
|
|
|
|
private SyncStrategy syncStrategy;
|
|
|
|
|
private LocalCachedMapOptions.StoreMode storeMode;
|
|
|
|
|
private LocalCachedMapOptions.ReadMode readMode;
|
|
|
|
|
private boolean storeCacheMiss;
|
|
|
|
|
private boolean isUseObjectAsCacheKey;
|
|
|
|
|
|
|
|
|
@ -84,6 +85,7 @@ public class RedissonLocalCachedMap<K, V> extends RedissonMap<K, V> implements R
|
|
|
|
|
}
|
|
|
|
|
syncStrategy = options.getSyncStrategy();
|
|
|
|
|
storeMode = options.getStoreMode();
|
|
|
|
|
readMode = options.getReadMode();
|
|
|
|
|
storeCacheMiss = options.isStoreCacheMiss();
|
|
|
|
|
isUseObjectAsCacheKey = options.isUseObjectAsCacheKey();
|
|
|
|
|
localCacheView = new LocalCacheView<>(options, this);
|
|
|
|
@ -100,6 +102,11 @@ public class RedissonLocalCachedMap<K, V> extends RedissonMap<K, V> implements R
|
|
|
|
|
return new CacheValue(key, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void reloadCache() {
|
|
|
|
|
RedissonLocalCachedMap.this.reloadCache();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
listener.add(cache, cacheKeyMap);
|
|
|
|
|
instanceId = listener.getInstanceId();
|
|
|
|
@ -216,7 +223,7 @@ public class RedissonLocalCachedMap<K, V> extends RedissonMap<K, V> implements R
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<Integer> sizeAsync() {
|
|
|
|
|
if (storeMode == LocalCachedMapOptions.StoreMode.LOCALCACHE) {
|
|
|
|
|
if (storeMode == LocalCachedMapOptions.StoreMode.LOCALCACHE || readMode == LocalCachedMapOptions.ReadMode.LOCALCACHE) {
|
|
|
|
|
return new CompletableFutureWrapper<>(cache.size());
|
|
|
|
|
}
|
|
|
|
|
return super.sizeAsync();
|
|
|
|
@ -229,7 +236,7 @@ public class RedissonLocalCachedMap<K, V> extends RedissonMap<K, V> implements R
|
|
|
|
|
CacheKey cacheKey = localCacheView.toCacheKey(key);
|
|
|
|
|
CacheValue cacheValue = cache.get(cacheKey);
|
|
|
|
|
if (cacheValue == null) {
|
|
|
|
|
if (storeMode == LocalCachedMapOptions.StoreMode.LOCALCACHE) {
|
|
|
|
|
if (storeMode == LocalCachedMapOptions.StoreMode.LOCALCACHE || readMode == LocalCachedMapOptions.ReadMode.LOCALCACHE) {
|
|
|
|
|
if (hasNoLoader()) {
|
|
|
|
|
return new CompletableFutureWrapper<>(false);
|
|
|
|
|
}
|
|
|
|
@ -276,7 +283,7 @@ public class RedissonLocalCachedMap<K, V> extends RedissonMap<K, V> implements R
|
|
|
|
|
|
|
|
|
|
CacheValue cacheValue = new CacheValue(null, value);
|
|
|
|
|
if (!cache.containsValue(cacheValue)) {
|
|
|
|
|
if (storeMode == LocalCachedMapOptions.StoreMode.LOCALCACHE) {
|
|
|
|
|
if (storeMode == LocalCachedMapOptions.StoreMode.LOCALCACHE || readMode == LocalCachedMapOptions.ReadMode.LOCALCACHE) {
|
|
|
|
|
return new CompletableFutureWrapper<>(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -295,7 +302,7 @@ public class RedissonLocalCachedMap<K, V> extends RedissonMap<K, V> implements R
|
|
|
|
|
return new CompletableFutureWrapper<>((V) cacheValue.getValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (storeMode == LocalCachedMapOptions.StoreMode.LOCALCACHE) {
|
|
|
|
|
if (storeMode == LocalCachedMapOptions.StoreMode.LOCALCACHE || readMode == LocalCachedMapOptions.ReadMode.LOCALCACHE) {
|
|
|
|
|
if (hasNoLoader()) {
|
|
|
|
|
return new CompletableFutureWrapper((Void) null);
|
|
|
|
|
}
|
|
|
|
@ -672,7 +679,7 @@ public class RedissonLocalCachedMap<K, V> extends RedissonMap<K, V> implements R
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (storeMode == LocalCachedMapOptions.StoreMode.LOCALCACHE) {
|
|
|
|
|
if (storeMode == LocalCachedMapOptions.StoreMode.LOCALCACHE || readMode == LocalCachedMapOptions.ReadMode.LOCALCACHE) {
|
|
|
|
|
if (hasNoLoader()) {
|
|
|
|
|
return new CompletableFutureWrapper<>(result);
|
|
|
|
|
}
|
|
|
|
@ -889,7 +896,7 @@ public class RedissonLocalCachedMap<K, V> extends RedissonMap<K, V> implements R
|
|
|
|
|
result.add((V) value.getValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (storeMode == LocalCachedMapOptions.StoreMode.LOCALCACHE) {
|
|
|
|
|
if (storeMode == LocalCachedMapOptions.StoreMode.LOCALCACHE || readMode == LocalCachedMapOptions.ReadMode.LOCALCACHE) {
|
|
|
|
|
return new CompletableFutureWrapper<>(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -932,7 +939,7 @@ public class RedissonLocalCachedMap<K, V> extends RedissonMap<K, V> implements R
|
|
|
|
|
result.put((K) value.getKey(), (V) value.getValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (storeMode == LocalCachedMapOptions.StoreMode.LOCALCACHE) {
|
|
|
|
|
if (storeMode == LocalCachedMapOptions.StoreMode.LOCALCACHE || readMode == LocalCachedMapOptions.ReadMode.LOCALCACHE) {
|
|
|
|
|
return new CompletableFutureWrapper<>(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -957,6 +964,19 @@ public class RedissonLocalCachedMap<K, V> extends RedissonMap<K, V> implements R
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void reloadCache() {
|
|
|
|
|
Set<CacheKey> existingCacheKeys = new HashSet<>(cache.keySet());
|
|
|
|
|
for (Entry<K, V> entry : super.entrySet(null, 10)) {
|
|
|
|
|
CacheKey cacheKey = localCacheView.toCacheKey(entry.getKey());
|
|
|
|
|
cachePut(cacheKey, entry.getKey(), entry.getValue());
|
|
|
|
|
existingCacheKeys.remove(cacheKey);
|
|
|
|
|
}
|
|
|
|
|
for (CacheKey cacheKey : existingCacheKeys) {
|
|
|
|
|
cacheRemove(cacheKey);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void preloadCache(int count) {
|
|
|
|
|
for (Entry<K, V> entry : super.entrySet(count)) {
|
|
|
|
@ -988,7 +1008,7 @@ public class RedissonLocalCachedMap<K, V> extends RedissonMap<K, V> implements R
|
|
|
|
|
result.add(new AbstractMap.SimpleEntry<K, V>((K) value.getKey(), (V) value.getValue()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (storeMode == LocalCachedMapOptions.StoreMode.LOCALCACHE) {
|
|
|
|
|
if (storeMode == LocalCachedMapOptions.StoreMode.LOCALCACHE || readMode == LocalCachedMapOptions.ReadMode.LOCALCACHE) {
|
|
|
|
|
return new CompletableFutureWrapper<>(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1322,7 +1342,7 @@ public class RedissonLocalCachedMap<K, V> extends RedissonMap<K, V> implements R
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Set<K> keySet(String pattern, int count) {
|
|
|
|
|
if (storeMode == LocalCachedMapOptions.StoreMode.LOCALCACHE) {
|
|
|
|
|
if (storeMode == LocalCachedMapOptions.StoreMode.LOCALCACHE || readMode == LocalCachedMapOptions.ReadMode.LOCALCACHE) {
|
|
|
|
|
return cachedKeySet();
|
|
|
|
|
}
|
|
|
|
|
return super.keySet(pattern, count);
|
|
|
|
@ -1330,7 +1350,7 @@ public class RedissonLocalCachedMap<K, V> extends RedissonMap<K, V> implements R
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Collection<V> values(String keyPattern, int count) {
|
|
|
|
|
if (storeMode == LocalCachedMapOptions.StoreMode.LOCALCACHE) {
|
|
|
|
|
if (storeMode == LocalCachedMapOptions.StoreMode.LOCALCACHE || readMode == LocalCachedMapOptions.ReadMode.LOCALCACHE) {
|
|
|
|
|
return cachedValues();
|
|
|
|
|
}
|
|
|
|
|
return super.values(keyPattern, count);
|
|
|
|
@ -1338,7 +1358,7 @@ public class RedissonLocalCachedMap<K, V> extends RedissonMap<K, V> implements R
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Set<Entry<K, V>> entrySet(String keyPattern, int count) {
|
|
|
|
|
if (storeMode == LocalCachedMapOptions.StoreMode.LOCALCACHE) {
|
|
|
|
|
if (storeMode == LocalCachedMapOptions.StoreMode.LOCALCACHE || readMode == LocalCachedMapOptions.ReadMode.LOCALCACHE) {
|
|
|
|
|
return cachedEntrySet();
|
|
|
|
|
}
|
|
|
|
|
return super.entrySet(keyPattern, count);
|
|
|
|
|