- java.lang.Object
-
- org.redkale.cached.spi.CachedManagerService
-
- 所有已实现的接口:
CachedManager,CachedActionFunc,Resourcable,Service
@Local @Component @AutoLoad(false) @ResourceType(CachedManager.class) public class CachedManagerService extends Object implements CachedManager, CachedActionFunc, Service
缓存管理器详情见: https://redkale.org
- 从以下版本开始:
- 2.8.0
- 作者:
- zhangjx
-
-
嵌套类概要
嵌套类 修饰符和类型 类 说明 classCachedManagerService.CacheRemoteListenerprotected static interfaceCachedManagerService.GetterFunc<R>protected static interfaceCachedManagerService.SetterAsyncFuncprotected static interfaceCachedManagerService.SetterSyncFunc
-
字段概要
字段 修饰符和类型 字段 说明 protected List<CachedAction>actionsprotected Applicationapplicationprotected ConcurrentHashMap<String,CachedAsyncLock>asyncLockMapprotected booleanbroadcastableprotected AnyValueconfigprotected booleanenabledprotected CachedLocalSourcelocalSourceprotected Loggerloggerprotected LevellogLevelprotected Stringnameprotected Stringnodeprotected CacheEventListenerremoteListenerprotected CacheSourceremoteSourceprotected Stringschemaprotected ConcurrentHashMap<String,CachedValue>syncLockMap-
从接口继承的字段 org.redkale.cached.CachedManager
CACHED_SCHEMA, CACHED_TOPIC
-
-
构造器概要
构造器 限定符 构造器 说明 protectedCachedManagerService(CacheSource remoteSource)
-
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 voidacceptCachedAction(String name, Consumer<CachedAction> consumer)处理指定缓存名称的CachedActionvoidaddAction(CachedAction action)longbothDel(String name, String key)远程删除缓存数据CompletableFuture<Long>bothDelAsync(String name, String key)远程异步删除缓存数据<T> TbothGet(String name, String key, Type type)远程获取缓存数据, 过期返回null<T> CompletableFuture<T>bothGetAsync(String name, String key, Type type)远程异步获取缓存数据, 过期返回nullprotected <T> CachedValue<T>bothGetCache(String name, String key, int localLimit, Duration expire, Type cacheType)protected <T> CompletableFuture<CachedValue<T>>bothGetCacheAsync(String name, String key, int localLimit, Duration expire, Type cacheType)远程异步获取缓存数据, 过期返回null<T> TbothGetSet(String name, String key, Type type, boolean nullable, int localLimit, Duration localExpire, Duration remoteExpire, ThrowSupplier<T> supplier)远程获取缓存数据, 过期返回null<T> CompletableFuture<T>bothGetSetAsync(String name, String key, Type type, boolean nullable, int localLimit, Duration localExpire, Duration remoteExpire, ThrowSupplier<CompletableFuture<T>> supplier)远程异步获取缓存数据, 过期返回null<T> voidbothSet(String name, String key, Type type, T value, Duration localExpire, Duration remoteExpire)远程缓存数据<T> CompletableFuture<Void>bothSetAsync(String name, String key, Type type, T value, Duration localExpire, Duration remoteExpire)远程异步缓存数据protected voidcheckEnable()protected StringcheckSchema(String value)检查schema是否含特殊字符static CachedManagerServicecreate(CacheSource remoteSource)voiddestroy(AnyValue conf)进程退出时,调用Service销毁 远程模式下该方法会重载成空方法 注意: 在此方法内不能调用MessageClient.sendMessage 方法,因为Application关闭时会先destroy掉MessageClientbooleanenabled()CachedManagerServiceenabled(boolean val)List<CachedAction>getCachedActions()获取CachedAction集合CachedLocalSourcegetLocalSource()StringgetNode()唯一标识CacheSourcegetRemoteSource()获取远程缓存Source, 可能为nullStringgetSchema()缓存的schema, 不能含有':'、'#'、'@'字符protected <T> TgetSet(CachedManagerService.GetterFunc<CachedValue<T>> getter, CachedManagerService.SetterSyncFunc setter, String name, String key, Type type, boolean nullable, int localLimit, Duration expire, ThrowSupplier<T> supplier)获取缓存数据, 过期返回nullprotected <T> CompletableFuture<T>getSetAsync(CachedManagerService.GetterFunc<CompletableFuture<CachedValue<T>>> getter, CachedManagerService.SetterAsyncFunc setter, String name, String key, Type type, boolean nullable, int localLimit, Duration expire, ThrowSupplier<CompletableFuture<T>> supplier)异步获取缓存数据, 过期返回nullprotected StringidFor(String name, String key)创建一个锁keyvoidinit(AnyValue conf)该方法必须是可以重复调用, 当reload时需要重复调用init方法 远程模式下该方法会重载成空方法booleanisEnabled()protected TypeloadCacheType(Type type)创建数据类型创建对应CacheValue泛型protected TypeloadCacheType(Type type, Object value)创建数据类型创建对应CacheValue泛型longlocalDel(String name, String key)本地删除缓存数据<T> TlocalGet(String name, String key, Type type)本地获取缓存数据, 过期返回null<T> TlocalGetSet(String name, String key, Type type, boolean nullable, int localLimit, Duration expire, ThrowSupplier<T> supplier)本地获取缓存数据, 过期返回null<T> CompletableFuture<T>localGetSetAsync(String name, String key, Type type, boolean nullable, int localLimit, Duration expire, ThrowSupplier<CompletableFuture<T>> supplier)本地异步获取缓存数据, 过期返回null<T> voidlocalSet(String name, String key, int localLimit, Type type, T value, Duration expire)本地缓存数据protected <T> voidlocalSetCache(String name, String key, int localLimit, Type type, T value, Duration expire)protected <T> voidlocalSetCache(String name, String key, int localLimit, Duration expire, Type cacheType, CachedValue<T> cacheVal)protected <T> CompletableFuture<Void>localSetCacheAsync(String name, String key, int localLimit, Type type, T value, Duration expire)protected <T> CompletableFuture<Void>localSetCacheAsync(String name, String key, int localLimit, Duration expire, Type cacheType, CachedValue<T> cacheVal)longremoteDel(String name, String key)远程删除缓存数据CompletableFuture<Long>remoteDelAsync(String name, String key)远程异步删除缓存数据<T> TremoteGet(String name, String key, Type type)远程获取缓存数据, 过期返回null<T> CompletableFuture<T>remoteGetAsync(String name, String key, Type type)远程异步获取缓存数据, 过期返回null<T> TremoteGetSet(String name, String key, Type type, boolean nullable, Duration expire, ThrowSupplier<T> supplier)远程获取缓存数据, 过期返回null<T> CompletableFuture<T>remoteGetSetAsync(String name, String key, Type type, boolean nullable, Duration expire, ThrowSupplier<CompletableFuture<T>> supplier)远程异步获取缓存数据, 过期返回null<T> voidremoteSet(String name, String key, Type type, T value, Duration expire)远程缓存数据<T> CompletableFuture<Void>remoteSetAsync(String name, String key, Type type, T value, Duration expire)远程异步缓存数据protected <T> voidremoteSetCache(String name, String key, int localLimit, Duration expire, Type cacheType, CachedValue<T> cacheVal)protected <T> voidremoteSetCache(String name, String key, Type type, T value, Duration expire)protected <T> voidremoteSetCache(String name, String key, Duration expire, Type cacheType, CachedValue<T> cacheVal)protected <T> CompletableFuture<Void>remoteSetCacheAsync(String name, String key, int localLimit, Type type, T value, Duration expire)protected <T> CompletableFuture<Void>remoteSetCacheAsync(String name, String key, int localLimit, Duration expire, Type cacheType, CachedValue<T> cacheVal)protected <T> CompletableFuture<Void>remoteSetCacheAsync(String name, String key, Duration expire, Type cacheType, CachedValue<T> cacheVal)StringresourceName()资源名称voidsetSchema(String schema)protected <T> ThrowSupplier<CachedValue<T>>toCacheSupplier(boolean nullable, ThrowSupplier<T> supplier)将原始数据函数转换成获取CacheValue数据函数protected <T> CachedValue<T>toCacheValue(boolean nullable, T value)将原始数据函数转换成获取CacheValue数据函数StringtoString()voidupdateBroadcastable(boolean broadcastable)-
从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
从接口继承的方法 org.redkale.cached.CachedManager
bothGetString, bothGetStringAsync, bothSetString, bothSetStringAsync, getChannelTopic, localGetString, localSet, localSetString, localSetString, remoteGetString, remoteGetStringAsync, remoteSetString, remoteSetStringAsync
-
-
-
-
字段详细资料
-
logger
protected final Logger logger
-
logLevel
protected Level logLevel
-
node
protected final String node
-
name
protected String name
-
schema
protected String schema
-
enabled
protected boolean enabled
-
broadcastable
protected boolean broadcastable
-
config
protected AnyValue config
-
localSource
protected final CachedLocalSource localSource
-
syncLockMap
protected final ConcurrentHashMap<String,CachedValue> syncLockMap
-
asyncLockMap
protected final ConcurrentHashMap<String,CachedAsyncLock> asyncLockMap
-
actions
protected final List<CachedAction> actions
-
application
protected Application application
-
remoteSource
protected CacheSource remoteSource
-
remoteListener
protected CacheEventListener remoteListener
-
-
构造器详细资料
-
CachedManagerService
protected CachedManagerService(@Nullable CacheSource remoteSource)
-
-
方法详细资料
-
create
public static CachedManagerService create(@Nullable CacheSource remoteSource)
-
enabled
public boolean enabled()
-
enabled
public CachedManagerService enabled(boolean val)
-
init
public void init(AnyValue conf)
从接口复制的说明:Service该方法必须是可以重复调用, 当reload时需要重复调用init方法 远程模式下该方法会重载成空方法
-
destroy
public void destroy(AnyValue conf)
从接口复制的说明:Service进程退出时,调用Service销毁 远程模式下该方法会重载成空方法 注意: 在此方法内不能调用MessageClient.sendMessage 方法,因为Application关闭时会先destroy掉MessageClient
-
resourceName
public String resourceName()
从接口复制的说明:CachedManager资源名称- 指定者:
resourceName在接口中CachedManager- 指定者:
resourceName在接口中Resourcable- 返回:
- 名称
-
getNode
public String getNode()
从接口复制的说明:CachedManager唯一标识- 指定者:
getNode在接口中CachedManager- 返回:
- node
-
getSchema
public String getSchema()
从接口复制的说明:CachedManager缓存的schema, 不能含有':'、'#'、'@'字符- 指定者:
getSchema在接口中CachedManager- 返回:
- schema
-
setSchema
public void setSchema(String schema)
-
isEnabled
public boolean isEnabled()
-
updateBroadcastable
public void updateBroadcastable(boolean broadcastable)
-
getLocalSource
public CachedLocalSource getLocalSource()
-
getRemoteSource
public CacheSource getRemoteSource()
获取远程缓存Source, 可能为null- 指定者:
getRemoteSource在接口中CachedManager- 返回:
CacheSource
-
addAction
public void addAction(CachedAction action)
- 指定者:
addAction在接口中CachedActionFunc
-
getCachedActions
public List<CachedAction> getCachedActions()
获取CachedAction集合- 指定者:
getCachedActions在接口中CachedManager- 返回:
- CachedAction集合
-
acceptCachedAction
public void acceptCachedAction(String name, Consumer<CachedAction> consumer)
处理指定缓存名称的CachedAction- 指定者:
acceptCachedAction在接口中CachedManager- 参数:
name- 缓存名称consumer- 处理函数
-
localGet
public <T> T localGet(String name, String key, Type type)
本地获取缓存数据, 过期返回null- 指定者:
localGet在接口中CachedManager- 类型参数:
T- 泛型- 参数:
name- 缓存名称key- 缓存键type- 数据类型- 返回:
- 数据值
-
localGetSet
public <T> T localGetSet(String name, String key, Type type, boolean nullable, int localLimit, Duration expire, ThrowSupplier<T> supplier)
本地获取缓存数据, 过期返回null- 指定者:
localGetSet在接口中CachedManager- 类型参数:
T- 泛型- 参数:
name- 缓存名称key- 缓存键type- 数据类型nullable- 是否缓存null值localLimit- 本地缓存数量上限expire- 过期时长,Duration.ZERO为永不过期supplier- 数据函数- 返回:
- 数据值
-
localGetSetAsync
public <T> CompletableFuture<T> localGetSetAsync(String name, String key, Type type, boolean nullable, int localLimit, Duration expire, ThrowSupplier<CompletableFuture<T>> supplier)
本地异步获取缓存数据, 过期返回null- 指定者:
localGetSetAsync在接口中CachedManager- 类型参数:
T- 泛型- 参数:
name- 缓存名称key- 缓存键type- 数据类型nullable- 是否缓存null值localLimit- 本地缓存数量上限expire- 过期时长,Duration.ZERO为永不过期supplier- 数据函数- 返回:
- 数据值
-
localSet
public <T> void localSet(String name, String key, int localLimit, Type type, T value, Duration expire)
本地缓存数据- 指定者:
localSet在接口中CachedManager- 类型参数:
T- 泛型- 参数:
name- 缓存名称key- 缓存键 *localLimit- 本地缓存数量上限type- 数据类型value- 数据值expire- 过期时长,Duration.ZERO为永不过期
-
localDel
public long localDel(String name, String key)
本地删除缓存数据- 指定者:
localDel在接口中CachedManager- 参数:
name- 缓存名称key- 缓存键- 返回:
- 删除数量
-
remoteGet
public <T> T remoteGet(String name, String key, Type type)
远程获取缓存数据, 过期返回null- 指定者:
remoteGet在接口中CachedManager- 类型参数:
T- 泛型- 参数:
name- 缓存名称key- 缓存键type- 数据类型- 返回:
- 数据值
-
remoteGetAsync
public <T> CompletableFuture<T> remoteGetAsync(String name, String key, Type type)
远程异步获取缓存数据, 过期返回null- 指定者:
remoteGetAsync在接口中CachedManager- 类型参数:
T- 泛型- 参数:
name- 缓存名称key- 缓存键type- 数据类型- 返回:
- 数据值
-
remoteGetSet
public <T> T remoteGetSet(String name, String key, Type type, boolean nullable, Duration expire, ThrowSupplier<T> supplier)
远程获取缓存数据, 过期返回null- 指定者:
remoteGetSet在接口中CachedManager- 类型参数:
T- 泛型- 参数:
name- 缓存名称key- 缓存键type- 数据类型nullable- 是否缓存null值expire- 过期时长,Duration.ZERO为永不过期supplier- 数据函数- 返回:
- 数据值
-
remoteGetSetAsync
public <T> CompletableFuture<T> remoteGetSetAsync(String name, String key, Type type, boolean nullable, Duration expire, ThrowSupplier<CompletableFuture<T>> supplier)
远程异步获取缓存数据, 过期返回null- 指定者:
remoteGetSetAsync在接口中CachedManager- 类型参数:
T- 泛型- 参数:
name- 缓存名称key- 缓存键type- 数据类型nullable- 是否缓存null值expire- 过期时长,Duration.ZERO为永不过期supplier- 数据函数- 返回:
- 数据值
-
remoteSet
public <T> void remoteSet(String name, String key, Type type, T value, Duration expire)
远程缓存数据- 指定者:
remoteSet在接口中CachedManager- 类型参数:
T- 泛型- 参数:
name- 缓存名称key- 缓存键type- 数据类型value- 数据值expire- 过期时长,Duration.ZERO为永不过期
-
remoteSetAsync
public <T> CompletableFuture<Void> remoteSetAsync(String name, String key, Type type, T value, Duration expire)
远程异步缓存数据- 指定者:
remoteSetAsync在接口中CachedManager- 类型参数:
T- 泛型- 参数:
name- 缓存名称key- 缓存键type- 数据类型value- 数据值expire- 过期时长,Duration.ZERO为永不过期- 返回:
- void
-
remoteDel
public long remoteDel(String name, String key)
远程删除缓存数据- 指定者:
remoteDel在接口中CachedManager- 参数:
name- 缓存名称key- 缓存键- 返回:
- 删除数量
-
remoteDelAsync
public CompletableFuture<Long> remoteDelAsync(String name, String key)
远程异步删除缓存数据- 指定者:
remoteDelAsync在接口中CachedManager- 参数:
name- 缓存名称key- 缓存键- 返回:
- 删除数量
-
bothGet
public <T> T bothGet(String name, String key, Type type)
远程获取缓存数据, 过期返回null- 指定者:
bothGet在接口中CachedManager- 类型参数:
T- 泛型- 参数:
name- 缓存名称key- 缓存键type- 数据类型- 返回:
- 数据值
-
bothGetAsync
public <T> CompletableFuture<T> bothGetAsync(String name, String key, Type type)
远程异步获取缓存数据, 过期返回null- 指定者:
bothGetAsync在接口中CachedManager- 类型参数:
T- 泛型- 参数:
name- 缓存名称key- 缓存键type- 数据类型- 返回:
- 数据值
-
bothGetSet
public <T> T bothGetSet(String name, String key, Type type, boolean nullable, int localLimit, Duration localExpire, Duration remoteExpire, ThrowSupplier<T> supplier)
远程获取缓存数据, 过期返回null- 指定者:
bothGetSet在接口中CachedManager- 类型参数:
T- 泛型- 参数:
name- 缓存名称key- 缓存键type- 数据类型nullable- 是否缓存null值localLimit- 本地缓存数量上限localExpire- 本地过期时长,Duration.ZERO为永不过期,为null表示不本地缓存remoteExpire- 远程过期时长,Duration.ZERO为永不过期,为null表示不远程缓存supplier- 数据函数- 返回:
- 数据值
-
bothGetSetAsync
public <T> CompletableFuture<T> bothGetSetAsync(String name, String key, Type type, boolean nullable, int localLimit, Duration localExpire, Duration remoteExpire, ThrowSupplier<CompletableFuture<T>> supplier)
远程异步获取缓存数据, 过期返回null- 指定者:
bothGetSetAsync在接口中CachedManager- 类型参数:
T- 泛型- 参数:
name- 缓存名称key- 缓存键type- 数据类型nullable- 是否缓存null值localLimit- 本地缓存数量上限localExpire- 本地过期时长,Duration.ZERO为永不过期,为null表示不本地缓存remoteExpire- 远程过期时长,Duration.ZERO为永不过期,为null表示不远程缓存supplier- 数据函数- 返回:
- 数据值
-
bothSet
public <T> void bothSet(String name, String key, Type type, T value, Duration localExpire, Duration remoteExpire)
远程缓存数据- 指定者:
bothSet在接口中CachedManager- 类型参数:
T- 泛型- 参数:
name- 缓存名称key- 缓存键type- 数据类型value- 数据值localExpire- 本地过期时长,Duration.ZERO为永不过期,为null表示不本地缓存remoteExpire- 远程过期时长,Duration.ZERO为永不过期,为null表示不远程缓存
-
bothSetAsync
public <T> CompletableFuture<Void> bothSetAsync(String name, String key, Type type, T value, Duration localExpire, Duration remoteExpire)
远程异步缓存数据- 指定者:
bothSetAsync在接口中CachedManager- 类型参数:
T- 泛型- 参数:
name- 缓存名称key- 缓存键type- 数据类型value- 数据值localExpire- 本地过期时长,Duration.ZERO为永不过期,为null表示不本地缓存remoteExpire- 远程过期时长,Duration.ZERO为永不过期,为null表示不远程缓存- 返回:
- void
-
bothDel
public long bothDel(String name, String key)
远程删除缓存数据- 指定者:
bothDel在接口中CachedManager- 参数:
name- 缓存名称key- 缓存键- 返回:
- 删除数量
-
bothDelAsync
public CompletableFuture<Long> bothDelAsync(String name, String key)
远程异步删除缓存数据- 指定者:
bothDelAsync在接口中CachedManager- 参数:
name- 缓存名称key- 缓存键- 返回:
- 删除数量
-
getSet
protected <T> T getSet(CachedManagerService.GetterFunc<CachedValue<T>> getter, CachedManagerService.SetterSyncFunc setter, String name, String key, Type type, boolean nullable, int localLimit, Duration expire, ThrowSupplier<T> supplier)
获取缓存数据, 过期返回null- 类型参数:
T- 泛型- 参数:
getter- 获取数据函数setter- 设置数据函数name- 缓存名称key- 缓存键type- 数据类型nullable- 是否缓存null值localLimit- 本地缓存数量上限expire- 过期时长,Duration.ZERO为永不过期supplier- 数据函数- 返回:
- 数据值
-
getSetAsync
protected <T> CompletableFuture<T> getSetAsync(CachedManagerService.GetterFunc<CompletableFuture<CachedValue<T>>> getter, CachedManagerService.SetterAsyncFunc setter, String name, String key, Type type, boolean nullable, int localLimit, Duration expire, ThrowSupplier<CompletableFuture<T>> supplier)
异步获取缓存数据, 过期返回null- 类型参数:
T- 泛型- 参数:
getter- 获取数据函数setter- 设置数据函数name- 缓存名称key- 缓存键type- 数据类型nullable- 是否缓存null值localLimit- 本地缓存数量上限expire- 过期时长,Duration.ZERO为永不过期supplier- 数据函数- 返回:
- 数据值
-
localSetCache
protected <T> void localSetCache(String name, String key, int localLimit, Type type, T value, Duration expire)
-
localSetCache
protected <T> void localSetCache(String name, String key, int localLimit, Duration expire, Type cacheType, CachedValue<T> cacheVal)
-
remoteSetCache
protected <T> void remoteSetCache(String name, String key, Type type, T value, Duration expire)
-
remoteSetCache
protected <T> void remoteSetCache(String name, String key, int localLimit, Duration expire, Type cacheType, CachedValue<T> cacheVal)
-
remoteSetCache
protected <T> void remoteSetCache(String name, String key, Duration expire, Type cacheType, CachedValue<T> cacheVal)
-
localSetCacheAsync
protected <T> CompletableFuture<Void> localSetCacheAsync(String name, String key, int localLimit, Type type, T value, Duration expire)
-
localSetCacheAsync
protected <T> CompletableFuture<Void> localSetCacheAsync(String name, String key, int localLimit, Duration expire, Type cacheType, CachedValue<T> cacheVal)
-
remoteSetCacheAsync
protected <T> CompletableFuture<Void> remoteSetCacheAsync(String name, String key, int localLimit, Type type, T value, Duration expire)
-
remoteSetCacheAsync
protected <T> CompletableFuture<Void> remoteSetCacheAsync(String name, String key, int localLimit, Duration expire, Type cacheType, CachedValue<T> cacheVal)
-
remoteSetCacheAsync
protected <T> CompletableFuture<Void> remoteSetCacheAsync(String name, String key, Duration expire, Type cacheType, CachedValue<T> cacheVal)
-
bothGetCache
protected <T> CachedValue<T> bothGetCache(String name, String key, int localLimit, Duration expire, Type cacheType)
-
bothGetCacheAsync
protected <T> CompletableFuture<CachedValue<T>> bothGetCacheAsync(String name, String key, int localLimit, Duration expire, Type cacheType)
远程异步获取缓存数据, 过期返回null- 类型参数:
T- 泛型- 参数:
name- 缓存名称key- 缓存键localLimit- 本地缓存数量上限expire- 过期时长,Duration.ZERO为永不过期cacheType- 数据类型- 返回:
- 数据值
-
checkEnable
protected void checkEnable()
-
toCacheValue
protected <T> CachedValue<T> toCacheValue(boolean nullable, T value)
将原始数据函数转换成获取CacheValue数据函数- 类型参数:
T- 泛型- 参数:
nullable- 是否缓存null值value- 缓存值- 返回:
- CacheValue函数
-
toCacheSupplier
protected <T> ThrowSupplier<CachedValue<T>> toCacheSupplier(boolean nullable, ThrowSupplier<T> supplier)
将原始数据函数转换成获取CacheValue数据函数- 类型参数:
T- 泛型- 参数:
nullable- 是否缓存null值supplier- 数据函数- 返回:
- CacheValue函数
-
loadCacheType
protected Type loadCacheType(Type type, Object value)
创建数据类型创建对应CacheValue泛型- 参数:
type- 数据类型,为null则取value的类型value- 数据值- 返回:
- CacheValue泛型
-
-