Cache<TIdentifier, TValue> class

An abstraction over Map that helps avoid paying construction costs for expensive objects.

Objects are created or existing ones returned with get or its async equivalent getAsync and marked as eligible for removal with release. If the TValue stored requires some sort of destruction this should be done in a callback registered with the didRemove stream.

References are retained for the lifecycle of the instance of the Cache, unless explicitly removed.

Mixed-in types

Constructors

Cache(CachingStrategy<TIdentifier, TValue> _cachingStrategy)

Properties

applyToItemCallBacks Map<TIdentifier, List<Future>>
no setter
didDispose Future<Null>
A Future that will complete when this object has been disposed.
no setterinherited
didRelease Stream<CacheContext<TIdentifier, TValue>>
A stream of CacheContexts that dispatches when an item is released from the cache.
no setter
didRemove Stream<CacheContext<TIdentifier, TValue>>
A stream of CacheContexts that dispatches when an item is removed from the cache.
no setter
didUpdate Stream<CacheContext<TIdentifier, TValue>>
The stream of CacheContexts that dispatches when an item is updated in the cache.
no setter
disposableTypeName String
A type name, similar to runtimeType but intended to work with minified code.
no setteroverride
disposalTreeSize int
The total size of the disposal tree rooted at the current Disposable instance.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
isDisposed bool
Whether this object has been disposed.
no setterinherited
isLeakFlagSet bool
Whether the leak flag for this object has been set.
no setterinherited
isOrWillBeDisposed bool
Whether the disposal of this object has been requested, is in progress, or is complete.
no setterinherited
liveKeys Iterable<TIdentifier>
Keys that have not been released.
no setter
liveValues Future<Iterable<TValue>>
Values that have not been released.
no setter
releasedKeys Iterable<TIdentifier>
Keys that have been released but are not yet removed.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

applyToItem(TIdentifier id, dynamic callback(Future<TValue> value)) Future<bool>
Returns true and calls callback if there is a cached, unreleased TValue associated with id; returns false otherwise.
awaitBeforeDispose<T>(Future<T> future) Future<T>
Add future to a list of futures that will be awaited before the object is disposed.
inherited
dispose() Future<Null>
Dispose of the object, cleaning up to prevent memory leaks.
inherited
flagLeak([String? description]) → void
Flag the object as having been disposed in a way that allows easier profiling.
inherited
get(TIdentifier id, Func<TValue> valueFactory) Future<TValue>
Returns a value from the cache for a given TIdentifier.
getAsync(TIdentifier id, Func<Future<TValue>> valueFactory) Future<TValue>
Returns a value from the cache for a given TIdentifier.
getManagedDelayedFuture<T>(Duration duration, T callback()) Future<T>
Creates a Future that will complete, with the value returned by callback, after the given amount of time has elapsed.
inherited
getManagedDisposer(Disposer disposer) ManagedDisposer
Automatically handle arbitrary disposals using a callback.
inherited
getManagedPeriodicTimer(Duration duration, void callback(Timer timer)) Timer
Creates a periodic Timer that will be cancelled if active upon disposal.
inherited
getManagedTimer(Duration duration, void callback()) Timer
Creates a Timer instance that will be cancelled if active upon disposal.
inherited
listenToStream<T>(Stream<T> stream, void onData(T event), {Function? onError, void onDone()?, bool? cancelOnError}) StreamSubscription<T>
Returns a StreamSubscription which handles events from the stream using the provided onData, onError and onDone handlers.
inherited
manageAndReturnTypedDisposable<T extends Disposable>(T disposable) → T
Automatically dispose another object when this object is disposed.
inherited
manageCompleter<T>(Completer<T> completer) Completer<T>
Ensure that a completer is completed when the object is disposed.
inherited
manageDisposable(Disposable disposable) → void
inherited
manageStreamController(StreamController controller) → void
Automatically cancel a stream controller when this object is disposed.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onDispose() Future<Null>
Callback to allow arbitrary cleanup on dispose.
inherited
onWillDispose() Future<Null>
Callback to allow arbitrary cleanup as soon as disposal is requested (i.e. dispose is called) but prior to disposal actually starting.
inherited
release(TIdentifier id) Future<Null>
Marks a TIdentifier TValue pair as eligible for removal.
remove(TIdentifier id) Future<Null>
Removes the reference to a TValue associated with the given TIdentifier.
toString() String
A string representation of this object.
inherited

Operators

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