CachetteBase<K, V extends Object, U extends Object> class
The base class for Cachette implementations.
You should probably use Cachette
or UserCachette
.
- Implementers
Constructors
-
CachetteBase(int size, {EvictionPolicy evictionPolicy = EvictionPolicy.leastRecentlyUsed, ConflictPolicy conflictPolicy = ConflictPolicy.overwrite, void onEvict(CacheEntry<
K, V, U> entry)?, Set<U> unevictableUsers = const {}})
Properties
- conflictPolicy → ConflictPolicy
-
Used to determine what should be done in the case of a key conflict.
final
-
entries
→ Iterable<
CacheEntry< K, V, U> > -
All items in the cache, in
CacheEntry
form.no setter - evictionPolicy → EvictionPolicy
-
Used to determine which items to evict when the cache becomes full.
final
-
evictionStream
→ Stream<
CacheEntry< K, V, U> > -
A stream of evicted cache entries.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
-
keys
→ Iterable<
K> -
All of the keys in the cache.
no setter
- length → int
-
The current number of items in the cache.
no setter
-
onEvict
→ (void Function(CacheEntry<
K, V, U> entry)?) -
Will be called each time an item is evicted.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- size → int
-
The maximum number of items the cache can hold.
final
-
unevictableUsers
→ Set<
U> -
If an entry is used by any of these users, it cannot be evicted.
final
-
values
→ Iterable<
V> -
All of the values in the cache.
no setter
Methods
-
add(
K key, V value, {ConflictPolicy? conflictPolicy, U? user, Set< U> ? users}) → Result<CacheEntry< K, V, U> , CachetteError> -
Adds a cache item with
key
andvalue
. UseconflictPolicy
to override the Cachette's conflict policy. Ifuser
orusers
are provided, they will be added to the cache item. Note that in order to use users,ConflictPolicy.users
must be used. Try saying the previous sentence out loud quickly. -
addUser(
K key, U user) → Result< CacheEntry< K, V, U> , CachetteError> -
Adds
user
to the cache item withkey
. Only works if the cache item already exists. -
addUsers(
K key, Set< U> users) → Result<CacheEntry< K, V, U> , CachetteError> -
Adds
users
to the cache item withkey
. Only works if the cache item already exists. -
clean(
{int? sizeLimit, EvictionPolicy? policy}) → Result< int, CachetteError> -
Cleans the cache, i.e. removes enough cache items to meet
sizeLimit
. IfsizeLimit
isn't provided, the size of the Cachette is used, which is the most likely use case.policy
can be used to override the Cachette's eviction policy. -
clear(
) → void - Removes all items from the cache.
-
containsKey(
K key) → bool -
Whether the cache contains an item with
key
. -
gather(
EvictionPolicy policy, int num) → List< K> -
Retries up to
num
items to be evicted according topolicy
. -
get(
K key) → Result< CacheEntry< K, V, U> , CachetteError> -
Gets a cache item with
key
. -
getUsers(
K key) → Result< Set< U> , CachetteError> -
Gets the list of all users registered to the cache item with
key
. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
remove(
K key, {bool callOnEvict = false}) → Result< CacheEntry< K, V, U> , CachetteError> -
Removes an item with
key
from the cache. -
removeUser(
K key, U user, {bool removeIfUnused = true, bool callOnEvict = true}) → Result< CacheEntry< K, V, U> , CachetteError> -
Removes a single
user
from thee cache item withkey
. IfremoveIfUnused
and the item has no users after removinguser
, it will be removed from the cache. -
removeUsers(
K key, Set< U> users, {bool removeIfUnused = true, bool callOnEvict = true}) → Result<CacheEntry< K, V, U> , CachetteError> -
Removes
users
from thee cache item withkey
. IfremoveIfUnused
and the item has no users after removingusers
, it will be removed from the cache. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator [](
K key) → V? -
operator []=(
K key, V value) → void