neat_cache
2.0.5, released a year ago by google.dev
A cache abstraction for wrapping in-memory or redis caches with timeouts.
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.
- hive_ce
If you need a lightweight NoSQL key-value database stored locally on the device.
96Compare - shared_preferences
If you just need simple key-value storage for primitive types.
97Compare
Works with
Packages commonly used together with neat_cache: ones it builds on, ones built on it, and its own family.
- asyncneat_cache depends on itUtility classes and helpers that extend Dart's async library.
- loggingneat_cache depends on itProvides configurable logging with levels and stream listeners for Dart apps.
- convertneat_cache depends on itEncoders and decoders for converting between different data representations.
- retryneat_cache depends on itProvides automatic retry with exponential back‑off for async functions.
- safe_url_checkSame familyCheck if an untrusted URL is broken without allowing connections to private IP addresses.
- neat_periodic_taskSame familyAuxiliary classes for reliably running periodic tasks in long-running processes.