SyncacheObserver class abstract
Observer interface for monitoring Syncache operations.
Implement this class to receive notifications about cache events such as hits, misses, fetches, and mutations. Useful for logging, analytics, debugging, and performance monitoring.
All methods have empty default implementations, so you only need to override the events you care about.
Example
class AnalyticsObserver extends SyncacheObserver {
@override
void onFetchSuccess(String key, Duration duration) {
analytics.track('cache_fetch', {
'key': key,
'duration_ms': duration.inMilliseconds,
});
}
@override
void onFetchError(String key, Object error, StackTrace stackTrace) {
errorReporter.report(error, stackTrace);
}
}
Usage
final cache = Syncache<User>(
store: MemoryStore(),
observers: [LoggingObserver(), AnalyticsObserver()],
);
- Implementers
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onCacheHit(
String key) → void - Called when a valid (non-expired) value is found in cache.
-
onCacheMiss(
String key) → void - Called when no value is found in cache, or the cached value is expired.
-
onClear(
) → void - Called when the entire cache is cleared.
-
onEvict(
String key) → void -
Called when an entry is evicted from a bounded store because the
store exceeded its capacity (e.g. least-recently-used eviction in a
MemoryStoreconfigured withmaxLength). -
onFetchCancelled(
String key) → void - Called when a fetch operation is cancelled via CancellationToken.
-
onFetchError(
String key, Object error, StackTrace stackTrace) → void - Called when a network fetch fails with an error.
-
onFetchStart(
String key) → void - Called when a network fetch operation starts.
-
onFetchSuccess(
String key, Duration duration) → void - Called when a network fetch completes successfully.
-
onInvalidate(
String key) → void - Called when a cache entry is explicitly invalidated.
-
onMutationConflict(
String key, Object error) → void - Called when a mutation's Mutation.send threw a SyncacheConflictException — the server reports the resource changed concurrently.
-
onMutationError(
String key, Object error, StackTrace stackTrace) → void - Called when a mutation's server sync fails.
-
onMutationResolved(
String key) → void - Called after a SyncacheConflictException was resolved: the ConflictResolver's value has been written to the cache and the mutation settled with a MutationResolved outcome — it is removed from the queue and will not be retried.
-
onMutationRetry(
String key, int attempt, Object error, Duration delay) → void - Called when a mutation sync fails and a retry is about to be attempted.
-
onMutationRetryExhausted(
String key, int totalAttempts, Object finalError) → void - Called when all mutation retry attempts have been exhausted.
-
onMutationStart(
String key) → void - Called when a mutation's optimistic update is applied locally.
-
onMutationSuccess(
String key) → void - Called when a mutation's server sync completes successfully.
-
onOutboxError(
Object error) → void - Called when an outbox write fails.
-
onOutboxReplayFailed(
PendingMutationRecord record, Object error) → void - Called when a persisted mutation record could not be turned back into a live mutation during Syncache.recoverPendingMutations.
-
onRetry(
String key, int attempt, Object error, Duration delay) → void - Called when a fetch fails and a retry is about to be attempted.
-
onRetryExhausted(
String key, int totalAttempts, Object finalError) → void - Called when all retry attempts have been exhausted.
-
onStore(
String key) → void - Called when a value is stored in the cache.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited