cached_value 0.1.0 copy "cached_value: ^0.1.0" to clipboard
cached_value: ^0.1.0 copied to clipboard

A simple way to cache values that result from rather expensive operations.

example/example.dart

import 'package:cached_value/cached_value.dart';

int factorial(int n) {
  if (n < 0) throw ('Negative numbers are not allowed.');
  return n <= 1 ? 1 : n * factorial(n - 1);
}

void main() {
  int originalValue = 1;
  final factorialCache = CachedValue.dependent(
    on: () => originalValue,
    compute: () => factorial(originalValue),
  );
  print(factorialCache.value); // 1

  originalValue = 6;

  print(factorialCache.value); // 720
}
13
likes
130
pub points
59%
popularity

Publisher

verified publisherblue-fire.xyz

A simple way to cache values that result from rather expensive operations.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

collection

More

Packages that depend on cached_value