pooled_map 1.0.0

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

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

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, web, other

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

Health suggestions

Fix lib/pooled_map.dart. (-1.99 points)

Analysis of lib/pooled_map.dart reported 4 hints:

line 22 col 33: Use = to separate a named parameter from its default value.

line 22 col 56: Use = to separate a named parameter from its default value.

line 26 col 30: Use = to separate a named parameter from its default value.

line 26 col 53: Use = to separate a named parameter from its default value.

Maintenance suggestions

Package is getting outdated. (-5.21 points)

The package was last published 54 weeks ago.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <3.0.0
pool ^1.0.0 1.4.0
Transitive dependencies
async 2.3.0
collection 1.14.11
path 1.6.2
stack_trace 1.9.3
Dev dependencies
test ^0.12.0

Admin