Skip to content
pubscout

cached

1.8.1, released a year ago by iteo.com

Simplifies and speeds up creation of in-memory and persistent caching mechanisms using code generation.

$ flutter pub add cached
Source repository

What it does

The package generates caching code for Dart classes and methods. It supports LRU eviction, time-to-live (TTL), conditional caching, persistent storage integration, and stream updates.

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

Use it when

  • You want to automatically cache API responses or expensive method calls in memory or persistent storage.
  • You need LRU cache eviction or TTL-based expiration without writing manual cache boilerplate.

Skip it when

  • You do not want to use code generation or build_runner in your project.
  • You need a general-purpose key-value store without class-level annotations.

Strengths

  • Reduces boilerplate for caching method results.
  • Supports LRU cache algorithm, TTL, and conditional caching via 'where'.
  • Supports persistent storage integrations and cache streams.

Weaknesses

  • Requires running build_runner for code generation.
  • Deprecated persistentStorage parameter requires migrating to newer annotations.

Setup

Kind
Pure Dart
Effort
Low
Code generation
Yes (build_runner)
Direct dependencies
7

Add cached and build_runner to dev_dependencies, add cached_annotation to dependencies, and run build_runner.

@WithCache()
abstract mixin class RemoteRepository implements Repository, _$RemoteRepository {
  factory RemoteRepository({required SomeApiDataSource dataSource}) = _RemoteRepository;

  @Cached()
  Future<SomeResponseType> getSthData() {
    return dataSource.getData();
  }
}

Alternatives

Packages that do the same job and could replace cached.

Works with

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