cached_query
3.7.1, released 3 weeks ago by cachedquery.dev
Library for caching, background fetching, and managing server state in Dart and Flutter.
What it does
It caches asynchronous function responses (such as API calls) against keys to provide fast UI loading and supports infinite lists, mutations, optimistic updates, and persistent storage. It can be used alongside existing state management options like Bloc or Provider.
AI-written summary of version 3.7.1, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need robust caching and background re-fetching for asynchronous server requests.
- You want support for infinite lists and optimistic updates during mutations.
Skip it when
- You are managing complex local client-only UI state rather than server state.
- You do not need asynchronous response caching or network request deduplication.
Strengths
- Automatic stale-while-revalidate caching mechanism
- Infinite query handling and built-in mutation support with optimistic updates
- Works alongside other state management options like Bloc or Provider
Weaknesses
- Requires proper key management and configuration for cache invalidation
- Persistent storage requires an additional package like cached_storage
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 2
Initialize global query configuration and optional storage at the start of your application.
Future<SomeData?> getCachedData() async {
final query = Query(key: "My key", queryFn: fetchData);
final queryState = await query.result;
return queryState.data;
}Alternatives
Packages that do the same job and could replace cached_query.
- riverpod
If you want a more comprehensive reactive caching and dependency injection solution built into your state management.
99Compare - bloc
If you prefer a strict event-driven state management pattern without built-in network caching abstractions.
92Compare - provider
If you need simple dependency injection and inherited widget-based state propagation.
81Compare
Works with
Packages commonly used together with cached_query: ones it builds on, ones built on it, and its own family.
- rxdartcached_query depends on itImplementation of the ReactiveX API for asynchronous programming leveraging native Dart Streams.
- cached_query_flutterBuilt on cached_queryWidgets and addons for Cached Query in Flutter including query and mutation builders.
- cached_storageBuilt on cached_queryAdds persistent storage to CachedQuery using Sqflite