All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.hotrod.near.ConcurrentMapNearCache Maven / Gradle / Ivy

There is a newer version: 14.0.32.Final
Show newest version
package org.infinispan.hotrod.near;

import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.infinispan.api.common.CacheEntry;
import org.infinispan.hotrod.configuration.NearCache;

/**
 * A concurrent-map-based near cache implementation.
 * It does not provide eviction capabilities.
 *
 * @since 14.0
 */
final class ConcurrentMapNearCache implements NearCache {

   private final ConcurrentMap> cache = new ConcurrentHashMap<>();

   @Override
   public boolean putIfAbsent(K key, CacheEntry entry) {
      return cache.putIfAbsent(key, entry) == null;
   }

   @Override
   public boolean replace(K key, CacheEntry prevValue, CacheEntry newValue) {
      return cache.replace(key, prevValue, newValue);
   }

   @Override
   public boolean remove(K key) {
      return cache.remove(key) != null;
   }

   @Override
   public boolean remove(K key, CacheEntry entry) {
      return cache.remove(key, entry);
   }

   @Override
   public CacheEntry get(K 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.values().stream().iterator();
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy