http_cache_flutterized 1.0.0 copy "http_cache_flutterized: ^1.0.0" to clipboard
http_cache_flutterized: ^1.0.0 copied to clipboard

A Simple http cache for flutter

A convienience package for caching http requests #

http_cache_flutter is a small package that makes it a little bit easier to cache http requests. To use it you also need the http package.

Using it is very easy:

import 'package:http_cache/src/http_chache.dart';
import 'package:http/http.dart' as http;

//jsonplaceholder is an api that returns jsonplaceholders
const url = 'https://jsonplaceholder.typicode.com/users';

void main(List<String> args) async {
  // first we initialize the cache
  await HttpCache.init();
  
  //we define the httpRequest
  final request = http.Request('GET', Uri.parse(url));
  //cacheGet returns a http.Response so you cant treat it like a regular http request
  final response = await HttpCache.cacheGet(request);
  //for me this call takes around 100 ms

  //if it is called a second time in your app it will get the cached response instead
  await HttpCache.cacheGet(request);
  //for me this call finished in 4 ms

  //to remove cached data associated with a url call [removeCache]
  HttpCache.removeCache(url);
}

The package uses the hive package to store and retrieve data.

This is the package that is modified for flutter. For the dart package see http_cache~

1
likes
140
points
22
downloads

Publisher

unverified uploader

Weekly Downloads

A Simple http cache for flutter

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

cupertino_icons, flutter, hive, hive_flutter, http

More

Packages that depend on http_cache_flutterized