Skip to content
pubscout

neat_cache

2.0.5, released a year ago by google.dev

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

Quiet but busy
$ flutter pub add neat_cache
Source repository

What it does

It provides a unified caching abstraction layer that can wrap in-memory or Redis stores. It supports sub-caches using prefixes, custom codecs like UTF-8, timeouts, and automatic reconnects.

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

Use it when

  • You need a consistent caching interface for Redis or in-memory stores.
  • You want to scope cached data using prefixes and apply custom data codecs.

Skip it when

  • You need local on-disk persistence like SQLite or Hive.
  • You require complex local key-value storage out of the box without setting up Redis.

Strengths

  • Provides a clean abstraction over different cache providers like Redis.
  • Supports prefixes and codecs for easy data serialization and scoping.

Weaknesses

  • Limited built-in provider options compared to larger caching libraries.
  • Testing Redis providers requires an external Redis instance.

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
5

Requires a running Redis instance if using the Redis cache provider.

import 'dart:async' show Future;
import 'dart:convert' show utf8;
import 'package:neat_cache/neat_cache.dart';

Future<void> main() async {
  final cacheProvider = Cache.redisCacheProvider('redis://localhost:6379');
  final cache = Cache(cacheProvider);

  final userCache = cache.withPrefix('users').withCodec(utf8);
  String userinfo = await userCache['peter-pan'].get();
  print(userinfo);

  await cacheProvider.close();
}

Alternatives

Packages that do the same job and could replace neat_cache.

Works with

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