dio_mcache 0.1.4 copy "dio_mcache: ^0.1.4" to clipboard
dio_mcache: ^0.1.4 copied to clipboard

HTTP cache interceptor for Dio built on mcache_dart. Per-request cache policies, tag invalidation, deduplication, conditional requests, and stale-while-revalidate.

example/main.dart

import 'package:dio/dio.dart';
import 'package:dio_mcache/dio_mcache.dart';

Future<void> main() async {
  final dio = Dio(BaseOptions(baseUrl: 'https://jsonplaceholder.typicode.com'));

  // Add the cache interceptor
  dio.interceptors.add(DioCacheInterceptor(
    options: DioCacheOptions(
      expiration: const Duration(minutes: 5),
      enableDeduplication: true,
    ),
  ));

  // First request — from network
  final response1 = await dio.get('/posts/1');
  print('First request: ${response1.extra['fromCache']}'); // null (network)

  // Second request — from cache
  final response2 = await dio.get('/posts/1');
  print('Second request: ${response2.extra['fromCache']}'); // true (cache)

  // Force refresh (skip cache)
  final response3 = await dio.get(
    '/posts/1',
    options: Options(extra: {'cacheControl': CacheControl.forceRefresh}),
  );
  print('Force refresh: ${response3.extra['fromCache']}'); // null (network)
}
0
likes
160
points
262
downloads

Documentation

API reference

Publisher

verified publisherpurplesoft.io

Weekly Downloads

HTTP cache interceptor for Dio built on mcache_dart. Per-request cache policies, tag invalidation, deduplication, conditional requests, and stale-while-revalidate.

Repository (GitHub)
View/report issues

Topics

#dio #cache #caching #http #flutter

License

AGPL-3.0 (license)

Dependencies

dio, mcache_dart

More

Packages that depend on dio_mcache