What does this package do?

  • Save last-modified header and data from http response to app database when making GET request the first time (only work if request method is GET and reponse header has last-modified). (1)
  • Append if-modified-since to request header if making the same GET request described in (1).
  • If reponse status code is 304, get the data from previous saved reponse and put it in data.

This package uses Hive as database resource with LRU cache strategy. If your project uses Hive too, please read below for advoiding conflict configuration.

Quick start:

  1. include the package to your project as dependency:
  	dio_304_cache: <latest version>
  1. In your main function, call initCache304Interceptor to initialize the database:
import 'package:dio_304_cache/dio_304_cache.dart';

void main() async {
  await initCache304Interceptor();
  1. Add Cache304Interceptorto dio instance interceptor:
    final dio = Dio();

Go to example project for full testing code.


  • When calling initCache304Interceptor, you can pass a Cache304Config object to adjust following properies:
Property nameTypeDefault ValueDescription
cacheLengthint25LRU is used for cache strategy, if saved data length exceeds this number, the one with least used will be removed.
cacheBoxNameStringdio_304_cache_hive_boxthe box name used to save data.
hiveInitPathStringuse path_provider as Hive path initpath to save your app data. If your app already called Hive.init(<your_path>), set this property to null to prevent re-initialization. Or you can provide your own path.


  await initCache304Interceptor(config: Cache304Config(cacheLength: 50));

To clear cache, use:

  await Cache304Interceptor.clearCache();