Package glide.api.models.configuration
Class ClientSideCache
- java.lang.Object
-
- glide.api.models.configuration.ClientSideCache
-
public class ClientSideCache extends java.lang.ObjectConfiguration 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
ClientSideCacheinstance. Clients with differentClientSideCacheinstances 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();
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classClientSideCache.ClientSideCacheBuilderCustomized builder that hides thecacheIdsetter and adds validation.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ClientSideCache.ClientSideCacheBuilderbuilder()static ClientSideCachecreate(long maxCacheKb, long entryTtlMs)Creates a ClientSideCache with auto-generated cache ID and default settings.java.lang.StringgetCacheId()Unique identifier for the cache instance.longgetEntryTtlMs()TTL (Time-To-Live) for cache entries in milliseconds.EvictionPolicygetEvictionPolicy()Eviction policy to use when cache reaches memory limit.longgetMaxCacheKb()Maximum memory limit for the cache in kilobytes.booleanisEnableMetrics()Whether to enable metrics collection for the cache.booleanisServerAssisted()Whether to enable server-assisted client-side caching.
-
-
-
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.
-
builder
public static ClientSideCache.ClientSideCacheBuilder builder()
-
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.
-
-