Class AttributeCache
-
- All Implemented Interfaces:
public class AttributeCache<K, V>thread safe
- Since:
2023-11-02
trydofor
-
-
Method Summary
Modifier and Type Method Description Class<out Object>getOwner()TypedReg<K, V>getTyped()StringgetName()intgetSize()intgetLive()intgetIdle()voidputAttr(@NotNull() K key, @NotNull() V value)Put key and value voidputAttr(@NotNull() K key, @NotNull() V value, int ttl)Put key and value with ttl voidputAttrs(@NotNull() Map<K, V> map)Put keys and values voidputAttrs(@NotNull() Map<K, V> map, int ttl)Put keys and values with ttl VtryAttr(@NotNull() K key, V elze)Try to get value by key, load it if not found, return `elze` if the result is null. VtryAttr(@NotNull() K key, V elze, int ttl)Try to get value by key, load it if not found, return `elze` if the result is null. VtryAttr(@NotNull() K key)Try to get an attribute by typed key, load it if not found, throw NPE if the result is null. VtryAttr(@NotNull() K key, int ttl)Try to get an attribute by typed key, load it if not found, throw NPE if the result is null. VtryAttr(@NotNull() K key, boolean notnull)Try to get an attribute by typed key, load it if not found, throw NPE if notnull and the result is null. VtryAttr(@NotNull() K key, boolean notnull, int ttl)Try to get an attribute by typed key, load it if not found, throw NPE if notnull and the result is null. VgetAttr(@NotNull() K key)Get an attribute by typed key, and NOT load if not found. Map<K, V>getAttrs(@NotNull() Collection<K> key)Get all attributes by typed keys, and NOT load if not found. voidridAttr(K key)remove an attribute by key voidridAttrs(Collection<out K> key)remove all attribute by keys voidridAttrAll()remove all attribute voidregister()register to the global voidunregister()unregister from the global static Set<TypedReg<out Object, out Object>>registered()thread safely list the registered types static <K, V> voidforEach(@NotNull() TypedReg<K, V> reg, @NotNull() Consumer<AttributeCache<K, V>> handle)thread safely loop the registered type voidsetLoader(Function<K, V> loader)-
-
Method Detail
-
getSize
int getSize()
-
getLive
int getLive()
-
getIdle
int getIdle()
-
putAttr
void putAttr(@NotNull() K key, @NotNull() V value)
Put key and value
- Parameters:
key- the keyvalue- the value
-
putAttr
void putAttr(@NotNull() K key, @NotNull() V value, int ttl)
Put key and value with ttl
- Parameters:
key- the keyvalue- the valuettl- time to live in second
-
putAttrs
void putAttrs(@NotNull() Map<K, V> map)
Put keys and values
- Parameters:
map- map of key-value
-
putAttrs
void putAttrs(@NotNull() Map<K, V> map, int ttl)
Put keys and values with ttl
- Parameters:
map- map of key-valuettl- time to live in second
-
tryAttr
@Contract(value = "_,!null->!null") V tryAttr(@NotNull() K key, V elze)
Try to get value by key, load it if not found, return `elze` if the result is null.
- Parameters:
key- unique key, e.g.elze- return `elze` if result is null
-
tryAttr
@Contract(value = "_,!null,_->!null") V tryAttr(@NotNull() K key, V elze, int ttl)
Try to get value by key, load it if not found, return `elze` if the result is null.
- Parameters:
key- unique key, e.g.elze- return `elze` if result is nullttl- ttl in second
-
tryAttr
@NotNull() V tryAttr(@NotNull() K key)
Try to get an attribute by typed key, load it if not found, throw NPE if the result is null.
- Parameters:
key- unique key, e.g.
-
tryAttr
@NotNull() V tryAttr(@NotNull() K key, int ttl)
Try to get an attribute by typed key, load it if not found, throw NPE if the result is null.
- Parameters:
key- unique key, e.g.ttl- ttl in second
-
tryAttr
@Contract(value = "_,true ->!null") V tryAttr(@NotNull() K key, boolean notnull)
Try to get an attribute by typed key, load it if not found, throw NPE if notnull and the result is null.
- Parameters:
key- unique key, e.g.notnull- whether notnull
-
tryAttr
@Contract(value = "_,true,_ ->!null") V tryAttr(@NotNull() K key, boolean notnull, int ttl)
Try to get an attribute by typed key, load it if not found, throw NPE if notnull and the result is null.
- Parameters:
key- unique key, e.g.notnull- whether notnullttl- ttl in second
-
getAttr
@Nullable() V getAttr(@NotNull() K key)
Get an attribute by typed key, and NOT load if not found.
- Parameters:
key- unique key, e.g.
-
getAttrs
@NotNull() Map<K, V> getAttrs(@NotNull() Collection<K> key)
Get all attributes by typed keys, and NOT load if not found.
- Parameters:
key- unique key, e.g.
-
ridAttrs
void ridAttrs(Collection<out K> key)
remove all attribute by keys
- Parameters:
key- unique key, e.g.
-
ridAttrAll
void ridAttrAll()
remove all attribute
-
register
void register()
register to the global
-
unregister
void unregister()
unregister from the global
-
registered
@NotNull() static Set<TypedReg<out Object, out Object>> registered()
thread safely list the registered types
-
forEach
static <K, V> void forEach(@NotNull() TypedReg<K, V> reg, @NotNull() Consumer<AttributeCache<K, V>> handle)
thread safely loop the registered type
-
-
-
-