Skip to content
pubscout

memoized

2.2.6, released 3 years ago by sylfree.com

Cache function results with optional LRU and expiry support

WASM-ready
$ flutter pub add memoized
Source repository

What it does

Wraps a function to store its return value so repeated calls with the same arguments return the cached result. Supports LRU caching for parameterized functions and manual expiration.

AI-written summary of version 2.2.6, based on the package's README and metadata. Report an inaccuracy

Use it when

  • Need to speed up expensive pure functions
  • Want to avoid recomputing results in a widget build
  • Implement memoization in non-Flutter Dart code

Skip it when

  • Using inside a build method without persisting the instance
  • Relying on memoization for side-effectful functions
  • When thread safety is required (not thread-safe)

Strengths

  • Simple API, no code generation
  • Supports LRU cache and manual expiry
  • Works across all Dart platforms
  • No external build_runner or permissions needed

Weaknesses

  • Not thread-safe
  • Requires careful instance management to avoid cache loss
  • No automatic cache invalidation for changing dependencies

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
1
import 'package:memoized/memoized.dart';

final sum = (() => 1.to(999999999).sum()).memo;
print(sum()); // computes
print(sum()); // cached

Alternatives

Packages that do the same job and could replace memoized.

Works with

Packages commonly used together with memoized: ones it builds on, ones built on it, and its own family.