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, dynamic value, Duration duration) {
    analytics.track('cache_fetch', {
      'key': key,
      'duration_ms': duration.inMilliseconds,
    });
  }

  @override
  void onError(String key, Object error, StackTrace stackTrace) {
    errorReporter.report(error, stackTrace);
  }
}

Usage

final cache = Syncache<User>(
  store: MemoryStore(),
  observers: [LoggingObserver(), AnalyticsObserver()],
);
Implementers

Constructors

SyncacheObserver()

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.
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.
onMutationError(String key, Object error, StackTrace stackTrace) → void
Called when a mutation's server sync fails.
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.
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