dcache_flutter 1.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 69

dcache_flutter #

Dcache_flutter is a library for Dio ( http client for flutter ). Dcache_flutter uses sqflite as disk cache and we consider that memery cache is unnecessary. It is used in our product. It is fully tested and stable. Maybe it's useful for you too.

Getting Started #

Add dependency #

dependencies:
  dcache_flutter: 1.0.2 #latest version

dcache 1.0.x is supported for dio 2.x dcache 1.1.x is supported for dio 3.x

Super simple to use #

import 'package:dcache_flutter/dcache.dart';

final encoder = DCacheEncoder();
final storage = DSqliteStorage(encoder: encoder);
final cacheDefaultOption = DCacheOptions(
    age: Duration(seconds: 120),
    policy: DCachePolicy.refreshFirst,
);
final cacheInterceptor = DCache(
    storage: storage,
    options: cacheDefaultOption,
);
dioInstance.interceptors.add(cacheInterceptor);

// clear cache
cacheInterceptor.storage.clearExpired();
// or
// cacheInterceptor.storage.clearAll();
  • DCacheEncoder: Encode and decode the key content of the response. It has a subclass named DBase64Encoder. Of course you can customize the encoder by inheriting DCacheEncoder, such as encryption.
  • DSqliteStorage: Store the response in sqlite. You can implement your own storage by inheriting DCacheStorage.
  • DCacheOptions: Provide age and policy of the cache.
  • DCachePolicy: Provide 3 kind of policy.
    • .cacheFirst: Use cache data first, if the cache data does not exist, then make the request.
    • .refreshFirst: Make request first, if the request returns an error, the cache is used.
    • .justRefresh: Just make request, and the response will be cached.
  • DCache: A subclass of Interceptor. So we can add it into dioInstance.interceptors.

Set different options for each request. #

final cacheOption = DCacheOptions(
    policy: DCachePolicy.cacheFirst,
);
final dioOptions = Options();
dioOptions.extra = cacheOption.toJson();
dioInstance().getUri(uri, options: dioOptions)

Features and bugs #

Please file feature requests and bugs at the issue tracker.

1.0.0 #

  • Dcache is a library for Dio ( http client for flutter ). Dcache uses sqflite as disk cache and we thought memery cache is unnecessary. It is used in our product. It is fully testd and stable. Maybe it's useful for you too.

1.0.1 #

  • Fix error of cocoapods.

1.0.2 #

  • iOS, swift -> Objc.

1.0.3 #

  • Fix android package id error.

1.1.0 #

  • Support for dio 3.x.

1.1.1 #

  • Fix android package id error.

example/lib/main.dart

import 'package:dcache_flutter_example/menu_view.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  @override
  void initState() {
    super.initState();
  }


  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MenuView(),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  dcache_flutter: ^1.1.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support 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:dcache_flutter/dcache.dart';
import 'package:dcache_flutter/dcache_encoder.dart';
import 'package:dcache_flutter/dcache_options.dart';
import 'package:dcache_flutter/dcache_storage.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
42
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
69
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health suggestions

Format lib/dcache_encoder.dart.

Run flutter format to format lib/dcache_encoder.dart.

Format lib/dcache_options.dart.

Run flutter format to format lib/dcache_options.dart.

Format lib/dcache_storage.dart.

Run flutter format to format lib/dcache_storage.dart.

Maintenance suggestions

The description is too long. (-10 points)

Search engines display only the first part of the description. Try to keep the value of the description field in your package's pubspec.yaml file between 60 and 180 characters.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
crypto ^2.1.3 2.1.4
dio ^3.0.0 3.0.9
flutter 0.0.0
sqflite ^1.1.5 1.3.0
Transitive dependencies
charcode 1.1.3
collection 1.14.11 1.14.12
convert 2.1.1
http_parser 3.1.4
meta 1.1.8
path 1.6.4
sky_engine 0.0.99
source_span 1.7.0
sqflite_common 1.0.0+1
string_scanner 1.0.5
synchronized 2.2.0
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test