ExpireCache<K, V> class

A FIFO cache. Its entries will expire after a given time period.

The cache entry will get remove when it is the first inserted entry and cache reach its limited size, or when it is expired.

You can use markAsInFlight to indicate that there will be a set call after. Then before this key's corresponding value is set, all the other get to this key will wait on the same Future.

Constructors

ExpireCache({Clock clock = const Clock(), Duration expireDuration = const Duration(seconds: 120), int sizeLimit = 100, Duration gcDuration = const Duration(seconds: 180)})

Properties

cache → dynamic
no setter
clock → Clock
The clock that uses to compute create_timestamp and expire.
final
expireDuration Duration
The duration between entry create and expire. Default 120 seconds
final
gcDuration Duration
The duration between each garbage collection. Default 180 seconds.
final
hashCode int
The hash code for this object.
no setterinherited
inflightSet → dynamic
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sizeLimit int
The upper size limit of _cache(the cache's max entry number).
final

Methods

clear() → void
containsKey(K key) bool
get(K key) Future<V?>
Returns the value associated with key.
inflightLength() int
The number of entry in the inflight set.
invalidate(K key) Future<Null>
Removes the value associated with key. The Future completes with null when the operation is complete.
isCacheEntryExpired(K key) bool
isEmpty() bool
Returns true if there is no entry in the cache. Doesn't matter if there is any inflight entry.
isInflightEntryExpire(K key) bool
isKeyInFlightOrInCache(K key) bool
length() int
The number of entry in the cache.
markAsInFlight(K key) Future<Null>
Mark a key as inflight. Calling this again or on a already cached entry will have no effect.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeFirst() → void
set(K key, V value) Future<Null>
Sets the value associated with key. The Future completes with null when the operation is complete.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited