cached_value
1.0.0, released 2 years ago by blue-fire.xyz
A simple way to cache values that result from expensive operations.
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.
- result_dart
Kotlin and Swift inspired Result class for error handling in Dart and Flutter.
69Compare - result_type
A Result type representing success or failure in Dart
50Compare - package_signature
Retrieve Android package signature (SHA1/SHA256) in a Flutter app.
66Compare - memoized
Cache function results with optional LRU and expiry support
45Compare
Works with
Packages commonly used together with cached_value: ones it builds on, ones built on it, and its own family.