http_get_cache

HTTP compliant cache for Dart and Flutter. This package is a wrapper around the http package that provides a simple way to cache responses using the 'Cache-Control', 'eTag' and 'Last-Modified' headers.

APACHE-2.0 License

Stars
20

http_get_cache

HTTP compliant cache for Flutter. This package is a wrapper around the http package that provides a simple way to cache responses using the 'Cache-Control', 'eTag' and 'Last-Modified' headers.

Dart

import 'package:http_get_cache/http_get_cache.dart';

void main() async {
    ...
    await initHttpGetCache(cachePath: '.cache', databasePath: '.db');

    // Create a new HTTP Client
    final client = httpClient();

    // Future<StreamedResponse>
    final res = await client.send('...');

    // Stream<StreamedResponse>
    final res = await client.stream('...');
}

Flutter

In the main.dart file you can add the following code:

import 'package:http_get_cache/http_get_cache_flutter.dart';

void main() async {
    ...
    await initFlutterHttpGetCache();
    
    // Create a new HTTP Client
    final client = httpClient();

    // Future<StreamedResponse>
    final res = await client.send('...');
    
    // Stream<StreamedResponse>
    final res = await client.stream('...');
}

When building the Flutter app you can remove the default client with the following variable:

--dart-define=no_default_http_client=true

Wrap with RetryClient

import 'package:http/retry.dart';

final client = RetryClient(httpClient());

Install via git:

http_get_cache:
    git:
      url: https://github.com/rodydavis/http_get_cache

See also