http_extensions_cache 0.1.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 67

http_extensions : cache #

An [http extension] that caches requests.

Usage #

final client = ExtendedClient(
  inner: Client(),
  extensions: [
        logger: Logger("Cache"),
        defaultOptions: CacheOptions(
          const CacheOptions(
            expiry: const Duration(minutes: 5),// The duration after the cached result of the request will be expired.
            forceUpdate: false, // Forces to request a new value, even if an valid cache is available
            forceCache: false, // Forces to return the cached value if available (even if expired).
            ignoreCache: true, //Indicates whether the request should bypass all caching logic
            returnCacheOnError: true, //If [true], on error, if a value is available in the  store if is returned as a successful response (even if expired). 
            keyBuilder: (request) => "${request.method}_${uuid.v5(Uuid.NAMESPACE_URL, request.uri.toString())}", // Builds the unqie key used for indexing a request in cache.
            store: MemoryCacheStore(), // The store used for caching data.
            shouldBeSaved: (response) => response.statusCode >= 200 && response.statusCode < 300, // A way of filtering responses (for exemple regarding the result status code, or the content length).

0.1.3 #

  • Added conditional platform imports.

0.1.0 #

  • Initial version


import 'package:http_extensions/http_extensions.dart';
import 'package:http_extensions_cache/http_extensions_cache.dart';
import 'package:http_extensions_cache/src/stores/memory_store.dart';
import 'package:logging/logging.dart';
import 'package:http/http.dart';

main() async {
  // Displaying logs
  Logger.root.level = Level.ALL;
  Logger.root.onRecord.listen((record) {
    print('${}: ${record.time}: ${record.message}');

  final store = MemoryCacheStore();

  final client = ExtendedClient(
    inner: Client(),
    extensions: [
          logger: Logger("Cache"), defaultOptions: CacheOptions(store: store)),

  // The first request will get data and add it to cache
  final distantResponse = await client.get("");
      "Distant -> statusCode: ${distantResponse.statusCode}, data : ${distantResponse.body.substring(0, 20)}...");

  await Future.delayed(const Duration(seconds: 5));

  // The second request will use the cached value
  final cachedResponse = await client.get("");
      "Cached -> statusCode: ${cachedResponse.statusCode}, data : ${distantResponse.body.substring(0, 20)}...");

  // The new request will get data and add it to cache
  final forcedResponse = await client.getWithOptions(
    options: [CacheOptions(forceUpdate: true)],
      "Forced -> statusCode: ${forcedResponse.statusCode}, data : ${forcedResponse.body.substring(0, 20)}...");

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  http_extensions_cache: ^0.1.3

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:http_extensions_cache/http_extensions_cache.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Health suggestions

Format lib/src/extension.dart.

Run dartfmt to format lib/src/extension.dart.

Format lib/src/options.dart.

Run dartfmt to format lib/src/options.dart.

Format lib/src/stores/memory_store.dart.

Run dartfmt to format lib/src/stores/memory_store.dart.

Format lib/src/stores/store.dart.

Run dartfmt to format lib/src/stores/store.dart.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
http ^0.12.0+1 0.12.0+4
http_extensions ^0.1.2 0.1.2
logging ^0.11.3 0.11.4
meta ^1.1.6 1.1.8
uuid ^2.0.2 2.0.4
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.12
convert 2.1.1
crypto 2.1.4
http_parser 3.1.3
path 1.6.4
pedantic 1.9.0
source_span 1.6.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6