Skip to content
pubscout

lru_cache

0.0.3, released 6 months ago by an unverified publisher

A simple least recently used (LRU) cache implementation in Dart.

WASM-readyUnverified publisher
$ flutter pub add lru_cache
Source repository

What it does

Provides an LRU cache data structure that keeps track of the most recently accessed items and automatically evicts the least recently used elements when capacity limits are met. It uses Dart's LinkedHashMap and supports thread-safe operations.

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

Use it when

  • You need an in-memory cache with a maximum capacity and automatic eviction of least recently used items.
  • You require thread-safe operations for concurrent cache access.

Skip it when

  • You need persistent storage that survives application restarts.
  • You need advanced distributed caching solutions.

Strengths

  • Thread-safe out of the box using synchronization.
  • Customizable size calculation through a sizeOf method.

Weaknesses

  • In-memory only, data is lost when the app terminates.
  • Limited feature set beyond basic LRU caching.

Setup

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

void main() {
  final cache = LruCache<String, String>(2);
  cache.put('key1', 'value1');
  cache.put('key2', 'value2');
  print(cache.get('key1'));
}

Alternatives

Packages that do the same job and could replace lru_cache.

  • neat_cache

    A cache abstraction for wrapping in-memory or redis caches with timeouts.

  • king_cache

    File‑ and IndexedDB‑based cache for API responses and markdown content.

  • cached

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

  • stock

    Dart package for async data loading, caching, and combining local and network data sources.

Works with

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