Class CacheDecorators

java.lang.Object
cloud.opencode.base.cache.CacheDecorators

public final class CacheDecorators extends Object
Cache Decorators - Fluent API for chaining cache decorators 缓存装饰器 - 用于链式组合缓存装饰器的流式 API

Provides a fluent builder pattern for composing multiple cache decorators in a clean, readable way.

提供流式构建器模式,以清晰易读的方式组合多个缓存装饰器。

Usage Examples | 使用示例:

// Chain multiple decorators
Cache<String, User> decorated = CacheDecorators.chain(cache)
    .withProtection()                    // Add BloomFilter + SingleFlight
    .withRefreshAhead(policy, loader)    // Add proactive refresh
    .withTimeout(Duration.ofSeconds(5))  // Add operation timeouts
    .withCopyOnRead(User::clone)         // Add copy-on-read
    .build();

// With custom protection configuration
Cache<String, User> decorated = CacheDecorators.chain(cache)
    .withProtection(p -> p
        .bloomFilter(1_000_000, 0.01)
        .negativeCache(Duration.ofMinutes(5)))
    .build();

Features | 主要功能:

  • Fluent decorator chaining API - 流式装饰器链式 API
  • Protection (BloomFilter + SingleFlight) - 保护(布隆过滤器 + SingleFlight)
  • Refresh-ahead support - 提前刷新支持
  • Timeout wrapping - 超时包装
  • Copy-on-read isolation - 读时复制隔离

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
  • Null-safe: Yes - 空值安全: 是
Since:
JDK 25, opencode-base-cache V2.0.2
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • chain

      public static <K,V> CacheDecorators.ChainBuilder<K,V> chain(Cache<K,V> cache)
      Start a decorator chain for the given cache 为给定的缓存开始装饰器链
      Type Parameters:
      K - key type | 键类型
      V - value type | 值类型
      Parameters:
      cache - the cache to decorate | 要装饰的缓存
      Returns:
      decorator chain builder | 装饰器链构建器