Record Class DistributedCacheConfig

java.lang.Object
java.lang.Record
cloud.opencode.base.cache.distributed.DistributedCacheConfig
Record Components:
name - the cache name | 缓存名称
keyPrefix - the key prefix for namespacing | 键前缀(用于命名空间)
defaultTtl - the default time-to-live | 默认过期时间
connectionTimeout - the connection timeout | 连接超时时间
operationTimeout - the operation timeout | 操作超时时间
maxRetries - the maximum number of retries | 最大重试次数
retryBackoff - the backoff duration between retries | 重试间隔
enableCompression - whether to enable value compression | 是否启用值压缩
compressionThreshold - the compression threshold in bytes | 压缩阈值(字节)
enableStats - whether to enable statistics | 是否启用统计
enableLocalCache - whether to enable local cache | 是否启用本地缓存
localCacheSize - the local cache size | 本地缓存大小
localCacheTtl - the local cache TTL | 本地缓存过期时间
keySerializer - the key serializer | 键序列化器
valueSerializer - the value serializer | 值序列化器
invalidationChannel - the cache invalidation channel name | 缓存失效通道名称

public record DistributedCacheConfig(String name, String keyPrefix, Duration defaultTtl, Duration connectionTimeout, Duration operationTimeout, int maxRetries, Duration retryBackoff, boolean enableCompression, int compressionThreshold, boolean enableStats, boolean enableLocalCache, int localCacheSize, Duration localCacheTtl, CacheSerializer<?> keySerializer, CacheSerializer<?> valueSerializer, String invalidationChannel) extends Record
Configuration for Distributed Cache 分布式缓存配置

Provides configuration options for distributed cache implementations.

为分布式缓存实现提供配置选项。

Usage Example | 使用示例:

DistributedCacheConfig config = DistributedCacheConfig.builder()
    .name("user-cache")
    .keyPrefix("user:")
    .defaultTtl(Duration.ofHours(1))
    .connectionTimeout(Duration.ofSeconds(5))
    .operationTimeout(Duration.ofSeconds(1))
    .maxRetries(3)
    .enableCompression(true)
    .compressionThreshold(1024)
    .build();

Features | 主要功能:

  • Connection and operation timeout configuration - 连接和操作超时配置
  • Key prefix support - 键前缀支持
  • Compression configuration - 压缩配置
  • Retry configuration - 重试配置

Usage Examples | 使用示例:

DistributedCacheConfig config = DistributedCacheConfig.builder()
    .name("users")
    .keyPrefix("user:")
    .defaultTtl(Duration.ofHours(1))
    .build();

Security | 安全性:

  • Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
  • Null-safe: Yes - 空值安全: 是
Since:
JDK 25, opencode-base-cache V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • DistributedCacheConfig

      public DistributedCacheConfig(String name, String keyPrefix, Duration defaultTtl, Duration connectionTimeout, Duration operationTimeout, int maxRetries, Duration retryBackoff, boolean enableCompression, int compressionThreshold, boolean enableStats, boolean enableLocalCache, int localCacheSize, Duration localCacheTtl, CacheSerializer<?> keySerializer, CacheSerializer<?> valueSerializer, String invalidationChannel)
      Creates an instance of a DistributedCacheConfig record class.
      Parameters:
      name - the value for the name record component
      keyPrefix - the value for the keyPrefix record component
      defaultTtl - the value for the defaultTtl record component
      connectionTimeout - the value for the connectionTimeout record component
      operationTimeout - the value for the operationTimeout record component
      maxRetries - the value for the maxRetries record component
      retryBackoff - the value for the retryBackoff record component
      enableCompression - the value for the enableCompression record component
      compressionThreshold - the value for the compressionThreshold record component
      enableStats - the value for the enableStats record component
      enableLocalCache - the value for the enableLocalCache record component
      localCacheSize - the value for the localCacheSize record component
      localCacheTtl - the value for the localCacheTtl record component
      keySerializer - the value for the keySerializer record component
      valueSerializer - the value for the valueSerializer record component
      invalidationChannel - the value for the invalidationChannel record component
  • Method Details

    • builder

      public static DistributedCacheConfig.Builder builder()
      Creates a new builder. 创建新的构建器。
      Returns:
      the builder - 构建器
    • withDefaults

      public static DistributedCacheConfig withDefaults(String name)
      Creates a default configuration with the given name. 使用给定名称创建默认配置。
      Parameters:
      name - the cache name - 缓存名称
      Returns:
      the config - 配置
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • name

      public String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • keyPrefix

      public String keyPrefix()
      Returns the value of the keyPrefix record component.
      Returns:
      the value of the keyPrefix record component
    • defaultTtl

      public Duration defaultTtl()
      Returns the value of the defaultTtl record component.
      Returns:
      the value of the defaultTtl record component
    • connectionTimeout

      public Duration connectionTimeout()
      Returns the value of the connectionTimeout record component.
      Returns:
      the value of the connectionTimeout record component
    • operationTimeout

      public Duration operationTimeout()
      Returns the value of the operationTimeout record component.
      Returns:
      the value of the operationTimeout record component
    • maxRetries

      public int maxRetries()
      Returns the value of the maxRetries record component.
      Returns:
      the value of the maxRetries record component
    • retryBackoff

      public Duration retryBackoff()
      Returns the value of the retryBackoff record component.
      Returns:
      the value of the retryBackoff record component
    • enableCompression

      public boolean enableCompression()
      Returns the value of the enableCompression record component.
      Returns:
      the value of the enableCompression record component
    • compressionThreshold

      public int compressionThreshold()
      Returns the value of the compressionThreshold record component.
      Returns:
      the value of the compressionThreshold record component
    • enableStats

      public boolean enableStats()
      Returns the value of the enableStats record component.
      Returns:
      the value of the enableStats record component
    • enableLocalCache

      public boolean enableLocalCache()
      Returns the value of the enableLocalCache record component.
      Returns:
      the value of the enableLocalCache record component
    • localCacheSize

      public int localCacheSize()
      Returns the value of the localCacheSize record component.
      Returns:
      the value of the localCacheSize record component
    • localCacheTtl

      public Duration localCacheTtl()
      Returns the value of the localCacheTtl record component.
      Returns:
      the value of the localCacheTtl record component
    • keySerializer

      public CacheSerializer<?> keySerializer()
      Returns the value of the keySerializer record component.
      Returns:
      the value of the keySerializer record component
    • valueSerializer

      public CacheSerializer<?> valueSerializer()
      Returns the value of the valueSerializer record component.
      Returns:
      the value of the valueSerializer record component
    • invalidationChannel

      public String invalidationChannel()
      Returns the value of the invalidationChannel record component.
      Returns:
      the value of the invalidationChannel record component