CachingTokenStorage class
A TokenStorage decorator that keeps an in-memory copy of the last written token so that read is effectively synchronous on the hot path.
Wrap any TokenStorage backend (e.g. flutter_secure_storage) with this
to avoid waiting for disk I/O on every request that calls
TokenKeeper.getValidToken():
final keeper = TokenKeeper(
storage: CachingTokenStorage(SecureStorageAdapter()),
refresher: ...,
);
All writes and deletes flow through to the backing store and update the cache atomically. If another process or isolate may modify the underlying store, call invalidate before reading to bypass the cache.
- Implemented types
Constructors
- CachingTokenStorage(TokenStorage _backing)
-
Creates a caching layer on top of
backing.
Properties
- cachedToken → Token?
-
Returns the cached token synchronously without going to the backing
store. Returns
nullif the cache has not been populated yet.no setter - hashCode → int
-
The hash code for this object.
no setterinherited
- isCached → bool
-
Whether the cache has been populated from the backing store.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
delete(
) → Future< void> -
Removes any stored token. A no-op if storage is empty.
override
-
invalidate(
) → void - Invalidates the cache so the next read fetches from the backing store.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
read(
) → Future< Token?> -
Returns the stored token or
nullif none was written.override -
refresh(
) → Future< Token?> - Invalidates the cache and immediately reloads from the backing store.
-
toString(
) → String -
A string representation of this object.
inherited
-
warmup(
) → Future< void> - Eagerly populates the cache from the backing store.
-
write(
Token token) → Future< void> -
Persists
token, replacing any previous entry.override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited