cachemesh 1.1.0
cachemesh: ^1.1.0 copied to clipboard
Result-first caching and data orchestration layer for Dart and Flutter apps. Memory-first cache with policies, single-flight dedup, and reactive watch streams.
Changelog #
1.1.0 #
Ecosystem integration — no breaking changes.
ResilifySource<T>typedef: alias forFetcher<T>so resilify pipelines read naturally at call sites. Any function returningFuture<Result<T>>plugs straight intoCache.get— no manual try/catch wrapping required.TokenKeeperAdapterinterface: bridgestoken_keeper'swithValidTokenflow into the cache. Pass an adapter viaCache(tokenKeeper: ...)and use the newCache.getAuthenticatedmethod — fetchers receive a valid token and the adapter is responsible for refreshing on unauthorized once.- Cache scopes: new
CacheScopeenum (global/session/user).Cache.get,refresh, andprefetchaccept an optionalscope:.Cache.scopeOf(key)reports the recorded scope. User-scoped reads requireCache.setActiveUser(id)to be called first. - Auto invalidation hooks:
Cache.setActiveUser(userId)— clears entries belonging to the previous user when the active user changes; no-op if unchanged.Cache.endSession()— drops both session- and user-scoped entries and unsets the active user. Call from your logout flow.Cache.clearScope(scope)— fine-grained, drop a single scope.
CacheLogger.onScopeCleared: new lifecycle event with the reason (setActiveUser,endSession,clearScope:<name>) and the list of removed keys. Only fires when there is at least one key to report.Cache.invalidateandCache.clearnow also clean up scope bookkeeping.
1.0.2 #
Smarter Result integration — no breaking changes.
- Failure-aware caching: pass
cacheFailures: truetoCacheor to individualget/refreshcalls to store failures in the cache (with TTL). The cached failure is returned on the next lookup instead of hitting the network. A successful re-fetch clears the stored failure automatically.Cache.hasCachedFailure(key)lets you check the state without fetching. - Retry hooks: new
RetryOptionstype (maxAttempts,retryWhen,delay). Set a cache-wide default viaCache(retryOptions: ...)and override per call.RetryOptions.noRetry(single attempt) is the default, so existing code is unaffected. Built-inretryWhenpredicate pattern makes it easy to skip retries on specific error types (e.g. auth errors). - Smarter SWR revalidation:
staleWhileRevalidatenow only kicks off a background refresh when the cached entry is actually stale. PassalwaysRevalidate: trueto restore the pre-1.0.2 behaviour. - Cleaner failure propagation: returned
Failureand thrown exceptions both flow through the same retry loop andCacheLogger.onErrorcall; the original error type and stack trace are preserved throughout.
1.0.1 #
Stability & observability — no breaking changes.
- Cache logger: pluggable
CacheLogger(hits, misses, writes, refreshes, invalidations, clears, errors) withRefreshSourcefor filtering. IncludesPrintCacheLoggerfor quick wiring. - Cache state insights: new
Cache.inspect<T>(key)returns aCacheState<T>snapshot —isPresent,isFresh,isStale,age,timeToExpiry,expiresAt. - Safer expiry: SWR no longer kicks off a redundant background refresh while one is already in flight. Tightens single-flight semantics.
- Better error propagation: fetcher failures (returned
Failureor thrown exceptions) are routed throughCacheLogger.onErrorwith their original stack trace.
1.0.0 #
Initial release.
Result<T>sealed type (Success<T>/Failure<T>) withfoldandmap.Cachewith five policies:cacheFirst,networkFirst,staleWhileRevalidate,networkOnly,cacheOnly.- In-memory
MemoryCacheStorewith per-entry TTL. - Single-flight deduplication of concurrent fetches per key.
- Reactive
watch(key)broadcast streams. - Manual control:
refresh,prefetch,invalidate,clear,peek. - Pluggable
CacheStoreinterface (disk adapters land in 1.2.0).