Class AbstractDistributedCache<K,​V>

  • Type Parameters:
    K - the type of keys
    V - the type of values
    All Implemented Interfaces:
    DistributedCache<K,​V>
    Direct Known Subclasses:
    KubernetesDistributedCache

    public abstract class AbstractDistributedCache<K,​V>
    extends Object
    implements DistributedCache<K,​V>
    Abstract base class for distributed cache implementations.

    This class provides common functionality for all distributed cache types including: consistent hashing with virtual nodes, memory management, metrics tracking, and pluggable communication protocols.

    Common Features:

    • Consistent Hashing: Virtual nodes for even data distribution
    • Memory Management: Per-node memory limits with eviction
    • Metrics: Comprehensive metrics collection
    • Communication: Pluggable communication protocols
    • Node Management: Dynamic cluster topology management
    Since:
    1.0.0
    • Method Detail

      • generateNodeId

        protected String generateNodeId()
        Generate a unique node ID for this cache instance. Subclasses can override this for platform-specific node identification.
      • initializeCluster

        protected abstract void initializeCluster()
        Initialize cluster-specific functionality. Subclasses should implement this for their specific discovery mechanism.
      • recordMemoryUsage

        protected void recordMemoryUsage​(long bytes)
      • recordMemoryRemoval

        protected void recordMemoryRemoval​(long bytes)
      • evictToFreeMemory

        protected void evictToFreeMemory​(long bytesToFree)
      • estimateSize

        protected long estimateSize​(K key,
                                    V value)
      • getAsync

        public CompletableFuture<V> getAsync​(K key)
        Description copied from interface: DistributedCache
        Gets a value from the cache with the specified consistency level.
        Specified by:
        getAsync in interface DistributedCache<K,​V>
        Parameters:
        key - the key
        Returns:
        CompletableFuture containing the value or null if not found
      • putAsync

        public CompletableFuture<Void> putAsync​(K key,
                                                V value)
        Description copied from interface: DistributedCache
        Puts a value in the cache with the specified consistency level.
        Specified by:
        putAsync in interface DistributedCache<K,​V>
        Parameters:
        key - the key
        value - the value
        Returns:
        CompletableFuture that completes when the operation is done
      • rebalance

        public CompletableFuture<Void> rebalance()
        Description copied from interface: DistributedCache
        Forces a manual rebalancing of the cache across nodes.

        This is typically done automatically, but can be triggered manually after adding or removing nodes from the cluster.

        Specified by:
        rebalance in interface DistributedCache<K,​V>
        Returns:
        CompletableFuture that completes when rebalancing is done
      • invalidateGlobally

        public CompletableFuture<Void> invalidateGlobally​(K key)
        Description copied from interface: DistributedCache
        Invalidates a key across all nodes in the cluster.
        Specified by:
        invalidateGlobally in interface DistributedCache<K,​V>
        Parameters:
        key - the key to invalidate
        Returns:
        CompletableFuture that completes when invalidation is propagated
      • remove

        public V remove​(K key)
      • getFromRemoteNode

        protected V getFromRemoteNode​(String nodeAddress,
                                      K key)
      • removeFromRemoteNode

        protected V removeFromRemoteNode​(String nodeAddress,
                                         K key)