memoize
3.0.0, released 6 years ago by wrike.com
Returns cached result of function call when inputs were not changed from previous invocation.
What it does
Provides memoization functions (memo0 through memo10, imemo0 through imemo10) to cache the results of function calls based on whether their input arguments have changed. Supports comparison via the equality operator or the identical function.
AI-written summary of version 3.0.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to cache expensive function calculations based on input parameters.
- You want a simple lazy cache for zero-argument function calls.
Skip it when
- You need persistent caching across app restarts.
- Your functions have side effects that must run on every invocation.
Strengths
- Simple and lightweight with no external dependencies.
- Supports multiple argument counts up to 10.
Weaknesses
- In-memory caching only, does not persist data.
- Limited to a maximum of 10 arguments per function.
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 0
import 'dart:math';
import 'package:memoize/memoize.dart';
void main() {
var rect1 = new Rectangle<int>(0, 0, 10, 10);
var rect2 = new Rectangle<int>(0, 0, 10, 10);
var func = memo1((Rectangle<int> a) => a.width * a.height);
print(func(rect1));
print(func(rect2)); // cached result is returned
}Alternatives
Packages that do the same job and could replace memoize.
- result_dart
Kotlin and Swift inspired Result class for error handling in Dart and Flutter.
69Compare - lazy_memo
Cached lazy variables and memoized functions for Dart.
72Compare - result_type
A Result type representing success or failure in Dart
50Compare
Works with
Packages commonly used together with memoize: ones it builds on, ones built on it, and its own family.