K - 输入参数类型V - 输出参数类型public class FunctionCached<K,V>
extends java.lang.Object
implements com.google.common.base.Function<K,V>
LoadingCache实现类型转转换接口Function,
当一个输入K的计算结果已经存在于缓存时,直接返回,无需再次计算,
避免对同一个输入数据多次重复计算。
适用于输入值与结果恒定对应的场景| 构造器和说明 |
|---|
FunctionCached(com.google.common.base.Function<K,V> getterFunction)
构造方法,
K 为
null时返回null |
FunctionCached(com.google.common.base.Function<K,V> getterFunction,
V defaultValue)
构造方法
|
FunctionCached(com.google.common.base.Function<K,V> getterFunction,
V defaultValue,
com.google.common.cache.CacheBuilder<java.lang.Object,java.lang.Object> cacheBuilder)
构造方法
|
| 限定符和类型 | 方法和说明 |
|---|---|
V |
apply(K input)
缓存调用
|
V |
get(K key)
缓存调用
|
V |
getUncached(K key)
非缓存调用
|
static <K,V> FunctionCached<K,V> |
of(com.google.common.base.Function<K,V> getterFunction)
|
static <K,V> FunctionCached<K,V> |
of(com.google.common.base.Function<K,V> getterFunction,
V defaultValue)
|
static <K,V> FunctionCached<K,V> |
of(com.google.common.base.Function<K,V> getterFunction,
V defaultValue,
com.google.common.cache.CacheBuilder<java.lang.Object,java.lang.Object> cacheBuilder)
|
public FunctionCached(com.google.common.base.Function<K,V> getterFunction, V defaultValue, com.google.common.cache.CacheBuilder<java.lang.Object,java.lang.Object> cacheBuilder)
getterFunction - 原类型转换接口实现defaultValue - K为null时返回的默认值cacheBuilder - 外部提供的CacheBuilder实例,为null则忽略public FunctionCached(com.google.common.base.Function<K,V> getterFunction, V defaultValue)
getterFunction - 原类型转换接口实现defaultValue - K为null时返回的默认值public V getUncached(K key)
key - key为null返回defaultValuepublic V get(K key)
key - key为null返回defaultValuepublic V apply(K input)
apply 在接口中 com.google.common.base.Function<K,V>get(Object),
Function.apply(java.lang.Object)public static <K,V> FunctionCached<K,V> of(com.google.common.base.Function<K,V> getterFunction, V defaultValue, com.google.common.cache.CacheBuilder<java.lang.Object,java.lang.Object> cacheBuilder)
getterFunction - defaultValue - cacheBuilder - 外部提供的CacheBuilder实例,为null则忽略FunctionCached(Function, Object, CacheBuilder)public static <K,V> FunctionCached<K,V> of(com.google.common.base.Function<K,V> getterFunction, V defaultValue)
getterFunction - defaultValue - of(Function, Object, CacheBuilder)public static <K,V> FunctionCached<K,V> of(com.google.common.base.Function<K,V> getterFunction)
getterFunction - of(Function, Object)Copyright © 2023. All Rights Reserved.