Skip to content
pubscout

dio_http_cache

0.3.0, released 5 years ago by an unverified publisher

Cache Dio HTTP responses using sqflite disk and LRU memory

Quiet but busyUnverified publisher
$ flutter pub add dio_http_cache
Source repository

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.

Works with

Packages commonly used together with dio_http_cache: ones it builds on, ones built on it, and its own family.