Skip to content
pubscout

cached_value

1.0.0, released 2 years ago by blue-fire.xyz

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

WASM-ready
$ flutter pub add cached_value
Source repository

What it does

Provides a CachedValue class that stores computed values and avoids recalculating them on every access. Supports manual invalidation, declarative dependencies, and time-to-live (TTL) expiration.

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

Use it when

  • You need to cache results of expensive operations or object instances across frames in render objects.
  • Values need to be automatically invalidated when specified dependencies change.
  • Values should expire automatically after a specific time-to-live duration.

Skip it when

  • You need persistent storage across app restarts.
  • Your dependency callback performs expensive operations.

Strengths

  • Simple and lightweight API for memory caching
  • Supports declarative dependency tracking and TTL out of the box
  • Useful for performance optimization in render objects and paint routines

Weaknesses

  • Memory-only cache with no built-in disk persistence
  • Dependency callbacks are executed on every value access

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
2
final factorialCache = CachedValue(() => factorial(originalValue)).withDependency(() => originalValue);

Alternatives

Packages that do the same job and could replace cached_value.

Works with

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