Skip to content
pubscout

ttl_cache

0.3.0, released 3 years ago by bryanoltman.com

In‑memory key‑value store with optional time‑to‑live expiration for entries.

WASM-ready
$ flutter pub add ttl_cache
Source repository

What it does

Provides a simple Dart map‑like API where each entry can automatically expire after a configurable duration. Entries without a TTL remain until manually removed.

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

Use it when

  • You need fast, temporary caching of data in memory
  • You want automatic expiration of cached values without external storage

Skip it when

  • Persistent storage across app restarts is required
  • You need disk‑based caching or large binary data handling

Strengths

  • Zero‑dependency, pure Dart implementation
  • Supports per‑entry TTL and a clear method
  • Lightweight and easy to use

Weaknesses

  • Data is lost when the app is terminated
  • No built‑in persistence or disk caching

Setup

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

void main() {
  final cache = TtlCache<String, int>(defaultTtl: Duration(seconds: 1));
  cache['a'] = 1; // expires after 1 s
  cache.set('b', 2, ttl: Duration(seconds: 3)); // custom TTL
  print(cache['a']); // 1
}

Alternatives

Packages that do the same job and could replace ttl_cache.

Works with

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