shared_preferences_cache 0.1.0+3

  • Readme
  • Changelog
  • Example
  • Installing
  • 56

shared_preferences_cache #

A Cache for Flutter based on Shared Preferences. It is similar to the package flutter_cache_manager but instead of caching cache downloaded files, shared_preferences_cache can cache plain values (int, double, string, bool). This comes in handy if you want to cache a result of an expensive operation or of an API call which cannot be cached with flutter_cache_manager.

Usage #

To use this plugin, add shared_preferences_cache as a dependency in your pubspec.yaml file.

Example #

import 'package:shared_preferences_cache/shared_preferences_cache.dart';

void main() async {
      SharedPreferencesCache spc =
          await SharedPreferencesCache.getInstance(Duration(minutes: 5));

      Future<int> Function() heavyFunction = () async {
        // This code will only be executed if...
        // 1. No value for the given key exists in the cache
        // or
        // 2. The cached value is older then the provided maxAge (5 days in this example)

        print('Doing some heavy calculations');
        return 42;
      };

      print(await spc.getInt('the_answer', heavyFunction));
      sleep(Duration(seconds: 1));
      print(await spc.getInt('the_answer', heavyFunction));
}

To Do #

  • Proper API documentation

Known Issues #

  • The library is not thread-safe. When used in parallel it can happen that the key and value pairs fall apart

[0.1.0] - Initial Release #

  • Initial Release.

example/main.dart

// Full example to come.
// Until then, see test case "Simple Usage"
// in test/shared_preferences_cache_test.dart

Use this package as a library

1. Depend on it

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


dependencies:
  shared_preferences_cache: ^0.1.0+3

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:shared_preferences_cache/shared_preferences_cache.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
13
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
56
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because of import path [package:shared_preferences_cache/shared_preferences_cache.dart, package:shared_preferences/shared_preferences.dart] that declares support for platforms: android, ios, macos, web

Package does not support Flutter platform windows

Because of import path [package:shared_preferences_cache/shared_preferences_cache.dart, package:shared_preferences/shared_preferences.dart] that declares support for platforms: android, ios, macos, web

Package not compatible with SDK dart

because of import path [shared_preferences_cache] that is in a package requiring null.

Health issues and suggestions

Document public APIs. (-1 points)

17 out of 17 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
shared_preferences ^0.5.6+3 0.5.7+3
shared_preferences_platform_interface ^1.0.3 1.0.4
Transitive dependencies
collection 1.14.12 1.14.13
flutter_web_plugins 0.0.0
meta 1.1.8
shared_preferences_macos 0.0.1+10
shared_preferences_web 0.1.2+7
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test