dio_http_cache
0.3.0, released 5 years ago by an unverified publisher
Cache Dio HTTP responses using sqflite disk and LRU memory
What it does
Stores HTTP responses locally and serves them based on maxAge and maxStale settings. It integrates as a Dio interceptor and can distinguish cache hits via a response header.
AI-written summary of version 0.3.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- Need offline support for Dio requests
- Want to reduce network traffic for repeat requests
- Require fine‑grained cache control per request
Skip it when
- Working with non‑Dio HTTP clients
- Need a global cache across multiple clients
- Complex cache invalidation logic beyond maxAge/maxStale
Strengths
- Easy to add as a Dio interceptor
- Configurable disk and memory cache limits
- Supports custom primary/sub keys and encryption
- Automatic stale handling and cache clearing
Weaknesses
- Depends on sqflite, adding a native dependency
- Only works with Dio, not http or other clients
- No built‑in support for cache purging policies beyond maxAge/maxStale
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- Yes (build_runner)
- Direct dependencies
- 7
Add dio_http_cache to pubspec, create DioCacheManager with CacheConfig, add its interceptor to Dio, optionally set buildCacheOptions on requests.
dio.interceptors.add(DioCacheManager(CacheConfig(baseUrl: "https://api.example.com")).interceptor);
final response = await dio.get(
"https://api.example.com/data",
options: buildCacheOptions(Duration(days: 7)),
);Alternatives
Packages that do the same job and could replace dio_http_cache.
- http2
An HTTP/2 implementation in Dart for low-level transport and pooled HTTP/2 requests.
91Compare - dio_web_adapter
Web and WASM HTTP client adapter for Dio.
83Compare - dio_cache_interceptor
Dio HTTP cache interceptor with multiple stores respecting HTTP directives.
87Compare - flutter_cache_manager_dio
A Dio‑based cache manager that extends flutter_cache_manager for downloading and caching files.
46Compare
Works with
Packages commonly used together with dio_http_cache: ones it builds on, ones built on it, and its own family.
- cryptodio_http_cache depends on itProvides SHA, MD5, and HMAC hashing functions for Dart.
- json_annotationdio_http_cache depends on itProvides annotations for json_serializable to generate JSON (de)serialization code.
- diodio_http_cache depends on itA powerful HTTP networking package for Dart and Flutter with interceptors and request cancellation.
- json_serializabledio_http_cache depends on itAutomatically generate code for converting Dart classes to and from JSON.
- quiverdio_http_cache depends on itA set of utility libraries for Dart containing collections, async tools, and testing helpers.
- sqflitedio_http_cache depends on itSQLite plugin for Flutter supporting iOS, Android and MacOS.