WeakReferenceStorage<K, V> class
A Storage with a fixed number of storable elements and a weak reference to elements which are specified to be evicted. This way the cache can grow until the garbage collector decides to remove the entries.
Note that we cannot guarantee to call the onEvict() method for all elements so better to NOT use this storage for items which should be evicted.
- Implemented types
-
- Storage<
K, V>
- Storage<
Constructors
-
WeakReferenceStorage({OnEvict<
K, V> ? onEvict})
Properties
-
entries
→ List<
CacheEntry< K, V> > -
Returns the available values. This violates the enclosing principle. Take
the return values with caution
no setteroverride
- hashCode → int
-
The hash code for this object.
no setterinherited
-
keys
→ List<
K> -
Returns the available keys. This violates the enclosing principle. Take
the return values with caution
no setteroverride
- length → int
-
Returns the approx number of items in the cache. Take this with a grain
of salt
no setteroverride
-
onEvict
→ OnEvict<
K, V> ? -
if onEvict is set that method is called whenever an entry is removed from the cache.
At the time the method is called the entry is already removed.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
clear(
) → void -
Clears the cache, evicts all entries
override
-
containsKey(
K key) → bool -
Only returns true if the key is contained in the strong reference list and
as such ensured to be available for most caches (except expirationCache)
override
-
get(
K key) → CacheEntry< K, V> ? -
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onCapacity(
K key) → CacheEntry< K, V> ? -
removes the entry denoted by
key
. This is called if the capacity is reached.override -
remove(
K key) → CacheEntry< K, V> ? -
removes the entry at position key. Returns the entry or null. Note that
the entry is already evicted.
override
-
removeInternal(
K key) → CacheEntry< K, V> ? -
override
-
set(
K key, CacheEntry< K, V> value) → Storage -
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator [](
K key) → CacheEntry< K, V> ? -
Same as get
override
-
operator []=(
K key, CacheEntry< K, V> value) → void -
Same as set
override