Cache<T> class
Core
A simple cache for SnowflakeEntitys.
The underlying implementation is a basic LRU cache, limited by CacheConfig.maxSize. Entities will not be added to the cache if CacheConfig.shouldCache returns false.
When the cache size exceeds CacheConfig.maxSize, items already in the
cache for which CacheConfig.shouldCache now returns false are removed
first, then items are removed starting from the least recently accessed or
updated until the cache size no longer exceeds the maximum size.
The underlying implementation is subject to change in future versions and should not be relied on.
Constructors
-
Cache(Nyxx client, String identifier, CacheConfig<
T> config) -
factory
Properties
- client → Nyxx
-
The client this cache is for.
no setter
-
config
→ CacheConfig<
T> -
The configuration for this cache.
final
-
entries
→ Iterable<
MapEntry< Snowflake, T> > -
The map entries of this Map.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- identifier → String
-
An identifier for this cache.
final
- isEmpty → bool
-
Whether there is no key/value pair in the map.
no setterinherited
- isNotEmpty → bool
-
Whether there is at least one key/value pair in the map.
no setterinherited
-
keys
→ Iterable<
Snowflake> -
The keys of this Map.
no setteroverride
- length → int
-
The number of key/value pairs in the map.
no setterinherited
- manager → CacheManager
-
The manager for this cache.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
values
→ Iterable<
T> -
The values of this Map.
no setterinherited
Methods
-
addAll(
Map< Snowflake, T> other) → void -
Adds all key/value pairs of
otherto this map.inherited -
addEntries(
Iterable< MapEntry< newEntries) → voidSnowflake, T> > -
Adds all key/value pairs of
newEntriesto this map.inherited -
cast<
RK, RV> () → Map< RK, RV> -
Provides a view of this map as having
RKkeys andRVinstances, if necessary.inherited -
clear(
) → void -
Removes all entries from the map.
override
-
containsKey(
Object? key) → bool -
Whether this map contains the given
key.override -
containsValue(
Object? value) → bool -
Whether this map contains the given
value.inherited -
filterItems(
) → void - Filter the items in this cache so that it obeys the config.
-
forEach(
void action(Snowflake key, T value)) → void -
Applies
actionto each key/value pair of the map.inherited -
map<
K2, V2> (MapEntry< K2, V2> transform(Snowflake key, T value)) → Map<K2, V2> -
Returns a new map where all entries of this map are transformed by
the given
convertfunction.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
putIfAbsent(
Snowflake key, T ifAbsent()) → T -
Look up the value of
key, or add a new entry if it isn't there.inherited -
remove(
Object? key) → T? -
Removes
keyand its associated value, if present, from the map.override -
removeWhere(
bool test(Snowflake key, T value)) → void -
Removes all entries of this map that satisfy the given
test.inherited -
scheduleFilterItems(
) → void - Schedule filterItems to be run, if it isn't already scheduled.
-
toString(
) → String -
A string representation of this object.
inherited
-
update(
Snowflake key, T update(T value), {T ifAbsent()?}) → T -
Updates the value for the provided
key.inherited -
updateAll(
T update(Snowflake key, T value)) → void -
Updates all values.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator [](
Object? key) → T? -
The value for the given
key, ornullifkeyis not in the map.override -
operator []=(
Snowflake key, T value) → void -
Associates the
keywith the givenvalue.override