pooled_map 1.0.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • new75

pooled_map

Pub build status

An asynchronous map for Dart that locks keys, to avoid the Thundering Herd problem.

package:pooled_map is best-suited for implementing caches of expensive operations (i.e. database lookups).

Notes

  • PooledMap is inherently asynchronous; therefore, it is incompatible with the standard Map. However, you can easily convert between the two.
  • PooledMap by default has lockEntireMap set to false, as this can become a bottleneck for Web applications. If you plan to frequently query length, keys, values, or clear the map, however, you may consider enabling it. Most applications will likely not need it.

Brief Example

import 'dart:async';
import 'package:pooled_map/pooled_map.dart';

main() async {
  // Even though we start 100000 simultaneous, asynchronous updates,
  // access is restricted to one-at-a-time.
  //
  // Thus, the output will be 100000.
  var i = 100000;
  var map = new PooledMap<String, int>(lockEntireMap: true);

  Future<int> increment() {
    return map.update('i', (i) => i + 1, defaultValue: () => 0);
  }

  var futures = new List<Future<int>>.generate(i, (_) => increment());
  await Future.wait(futures);
  var value = await map['i'];
  print('$value == 100000');
}

1.0.0

  • Initial version.

example/main.dart

import 'dart:async';
import 'package:pooled_map/pooled_map.dart';

main() async {
  // Even though we start 100000 simultaneous, asynchronous updates,
  // access is restricted to one-at-a-time.
  //
  // Thus, the output will be 100000.
  var i = 100000;
  var map = new PooledMap<String, int>(lockEntireMap: true);

  Future<int> increment() {
    return map.update('i', (i) => i + 1, defaultValue: () => 0);
  }

  var futures = new List<Future<int>>.generate(i, (_) => increment());
  await Future.wait(futures);
  var value = await map['i'];
  print('$value == 100000');
}

Use this package as a library

1. Depend on it

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


dependencies:
  pooled_map: "^1.0.0"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


      import 'package:pooled_map/pooled_map.dart';
  
Version Uploaded Documentation Archive
1.0.0 Jun 28, 2018 Go to the documentation of pooled_map 1.0.0 Download pooled_map 1.0.0 archive

Analysis

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

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
50 / 100
Health:
Code health derived from static analysis. [more]
100 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
75
Learn more about scoring.

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:pooled_map/pooled_map.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <3.0.0
pool ^1.0.0 1.3.5
Transitive dependencies
async 2.0.7
collection 1.14.10
path 1.6.1
stack_trace 1.9.2
Dev dependencies
test ^0.12.0