Class ClientSideCache


  • public class ClientSideCache
    extends java.lang.Object
    Configuration for client-side caching. Client-side caching reduces network round-trips and server load by storing frequently accessed data locally on the client.

    Use the create(long, long) factory method or the builder to create instances. The cache ID is auto-generated internally.

    In order for 2 clients to share the same cache, they must be created with the same ClientSideCache instance. Clients with different ClientSideCache instances will have separate caches, even if the configurations are identical.

    Example:
    
     // Create cache with default settings
     ClientSideCache cache = ClientSideCache.create(1024, 60000);
    
     // Create cache with custom configuration
     ClientSideCache cache = ClientSideCache.builder()
         .maxCacheKb(2048)
         .entryTtlMs(300)
         .evictionPolicy(EvictionPolicy.LRU)
         .enableMetrics(true)
         .build();
     
    • Method Detail

      • create

        public static ClientSideCache create​(long maxCacheKb,
                                             long entryTtlMs)
        Creates a ClientSideCache with auto-generated cache ID and default settings.
        Parameters:
        maxCacheKb - Maximum memory limit for the cache in kilobytes.
        entryTtlMs - TTL for cache entries in milliseconds. Use 0 for no expiration.
        Returns:
        A new ClientSideCache instance with auto-generated ID.
      • getCacheId

        public java.lang.String getCacheId()
        Unique identifier for the cache instance. Auto-generated internally. Used to determine cache sharing between clients.
      • getMaxCacheKb

        public long getMaxCacheKb()
        Maximum memory limit for the cache in kilobytes.
      • getEntryTtlMs

        public long getEntryTtlMs()
        TTL (Time-To-Live) for cache entries in milliseconds. A value of 0 means no expiration. This field is required.
      • getEvictionPolicy

        public EvictionPolicy getEvictionPolicy()
        Eviction policy to use when cache reaches memory limit. Defaults to LRU if not specified.
      • isEnableMetrics

        public boolean isEnableMetrics()
        Whether to enable metrics collection for the cache. Defaults to false.
      • isServerAssisted

        public boolean isServerAssisted()
        Whether to enable server-assisted client-side caching.

        When enabled, GLIDE sends CLIENT TRACKING ON BCAST during connection setup and the server sends invalidation messages when tracked keys are modified. Requires RESP3 protocol. Defaults to false.