|
|
|
@ -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;
|
|
|
|
|
|
|
|
|
@ -78,6 +79,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);
|
|
|
|
@ -94,6 +96,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();
|
|
|
|
@ -213,7 +220,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();
|
|
|
|
@ -226,7 +233,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);
|
|
|
|
|
}
|
|
|
|
@ -273,7 +280,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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -292,7 +299,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);
|
|
|
|
|
}
|
|
|
|
@ -669,7 +676,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);
|
|
|
|
|
}
|
|
|
|
@ -921,7 +928,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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -964,7 +971,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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -989,6 +996,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)) {
|
|
|
|
@ -1020,7 +1040,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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1354,7 +1374,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);
|
|
|
|
@ -1362,7 +1382,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);
|
|
|
|
@ -1370,7 +1390,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);
|
|
|
|
|