dio_304_cache 0.0.3
dio_304_cache: ^0.0.3

Flutter Android iOS

A new Flutter plugin for caching http response data and append to 304 response

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:
dependencies:
  	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 {
  WidgetsFlutterBinding.ensureInitialized();
  await initCache304Interceptor();
  runApp(MyApp());
}
  1. Add Cache304Interceptorto dio instance interceptor:
    final dio = Dio();
    dio.interceptors.add(Cache304Interceptor());

Go to example project for full testing code.

Configuration: #

  • 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.

example:

  await initCache304Interceptor(config: Cache304Config(cacheLength: 50));
2
likes
100
pub points
45%
popularity

A new Flutter plugin for caching http response data and append to 304 response

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

ncluu95@gmail.com

License

BSD (LICENSE)

Dependencies

dio, flutter, hive, path_provider

More

Packages that depend on dio_304_cache