org.infinispan.client.hotrod.near.ConcurrentMapNearCache Maven / Gradle / Ivy
package org.infinispan.client.hotrod.near;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.infinispan.client.hotrod.MetadataValue;
/**
* A concurrent-map-based near cache implementation.
* It does not provide eviction capabilities.
*
* @since 7.1
*/
final class ConcurrentMapNearCache implements NearCache {
private final ConcurrentMap> cache = new ConcurrentHashMap<>();
@Override
public boolean putIfAbsent(K key, MetadataValue value) {
return cache.putIfAbsent(key, value) == null;
}
@Override
public boolean replace(K key, MetadataValue prevValue, MetadataValue newValue) {
return cache.replace(key, prevValue, newValue);
}
@Override
public boolean remove(K key) {
return cache.remove(key) != null;
}
@Override
public boolean remove(K key, MetadataValue value) {
return cache.remove(key, value);
}
@Override
public MetadataValue get(Object key) {
return cache.get(key);
}
@Override
public void clear() {
cache.clear();
}
@Override
public int size() {
return cache.size();
}
public static NearCache create() {
return new ConcurrentMapNearCache();
}
@Override
public Iterator>> iterator() {
return cache.entrySet().iterator();
}
}