Class NearCache<K,V>

java.lang.Object
com.loomcache.client.cache.NearCache<K,V>
Type Parameters:
K - key type
V - value type

public class NearCache<K,V> extends Object
Client-side near-cache for frequently accessed entries.

Stores frequently accessed cache entries locally to reduce network round-trips. Supports configurable max size, TTL, and eviction policies (LRU, LFU, Random). Thread-safe using ConcurrentHashMap with minimal locking for eviction.

  • Constructor Details

    • NearCache

      public NearCache(NearCache.NearCacheConfig config)
      Create a new near cache with the given configuration.
      Parameters:
      config - the near cache configuration (must not be null)
      Throws:
      NullPointerException - if config is null
  • Method Details

    • get

      public @Nullable V get(K key)
      Get a value from the cache. Returns null if not found or expired.
    • put

      public void put(K key, V value)
      Put a key-value pair into the cache.
    • remove

      public void remove(K key)
      Remove a key from the cache.
    • invalidate

      public void invalidate(K key)
      Invalidate a single key.
    • invalidateAll

      public void invalidateAll()
      Invalidate all entries.
    • size

      public int size()
      Get cache size.
    • getStats

      public NearCache.NearCacheStats getStats()
      Get cache statistics.
    • getDetailedStats

      public NearCache.NearCacheStats getDetailedStats()
      Get detailed cache statistics.
    • clearStats

      public void clearStats()
      Clear all statistics.
    • preload

      public void preload(Map<K,V> entries)
      Preload multiple entries into the cache.
      Parameters:
      entries - map of entries to load
    • getEvictionPolicy

      public String getEvictionPolicy()
      Get the current eviction policy name.
      Returns:
      the eviction policy name
    • setEvictionPolicy

      public void setEvictionPolicy(NearCache.EvictionPolicy policy)
      Set the eviction policy.
      Parameters:
      policy - the new eviction policy
    • getEntryMetadata

      public @Nullable NearCache.CacheEntryMetadata getEntryMetadata(K key)
      Get metadata for a cache entry.
      Parameters:
      key - the key to look up
      Returns:
      cache entry metadata or null if not found
    • getCacheEfficiency

      public NearCache.CacheEfficiency getCacheEfficiency()
      Get cache efficiency metrics.
      Returns:
      cache efficiency metrics
    • shutdown

      public void shutdown()
      Shutdown the cache and cleanup resources.