Class ReadThroughCache.Builder<K,V>

java.lang.Object
cloud.opencode.base.cache.ReadThroughCache.Builder<K,V>
Type Parameters:
K - key type | 键类型
V - value type | 值类型
Enclosing class:
ReadThroughCache<K,V>

public static class ReadThroughCache.Builder<K,V> extends Object
Builder for ReadThroughCache ReadThroughCache 构建器
Since:
JDK 25, opencode-base-cache V2.0.4
Author:
Leon Soo www.LeonSoo.com
  • Method Details

    • loader

      public ReadThroughCache.Builder<K,V> loader(Function<? super K, ? extends V> loader)
      Set the loader function for single key loading 设置单键加载函数
      Parameters:
      loader - the loader function | 加载函数
      Returns:
      this builder | 此构建器
    • loader

      public ReadThroughCache.Builder<K,V> loader(CacheLoader<K,V> loader)
      Set the loader using CacheLoader interface 使用 CacheLoader 接口设置加载器
      Parameters:
      loader - the cache loader | 缓存加载器
      Returns:
      this builder | 此构建器
    • batchLoader

      public ReadThroughCache.Builder<K,V> batchLoader(Function<? super Set<? extends K>, ? extends Map<K,V>> batchLoader)
      Set the batch loader function 设置批量加载函数
      Parameters:
      batchLoader - the batch loader function | 批量加载函数
      Returns:
      this builder | 此构建器
    • fallback

      public ReadThroughCache.Builder<K,V> fallback(Function<? super K, ? extends V> fallback)
      Set the fallback function for when loading returns null 设置加载返回 null 时的降级函数
      Parameters:
      fallback - the fallback function | 降级函数
      Returns:
      this builder | 此构建器
    • fallback

      public ReadThroughCache.Builder<K,V> fallback(V fallbackValue)
      Set a static fallback value 设置静态降级值
      Parameters:
      fallbackValue - the fallback value | 降级值
      Returns:
      this builder | 此构建器
    • cacheNullValues

      public ReadThroughCache.Builder<K,V> cacheNullValues()
      Enable caching of null values (using fallback as marker) 启用缓存 null 值(使用降级值作为标记)
      Returns:
      this builder | 此构建器
    • build

      public ReadThroughCache<K,V> build()
      Build the read-through cache 构建读穿透缓存
      Returns:
      read-through cache | 读穿透缓存