neat_cache 2.0.4 copy "neat_cache: ^2.0.4" to clipboard
neat_cache: ^2.0.4 copied to clipboard

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

Neat Cache #

Abstractions around in-memory caches stores such as redis, with timeouts and automatic reconnects.

Disclaimer: This is not an officially supported Google product.

Example #

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);

  /// Create a sub-cache using a prefix, and apply a codec to store utf8
  final userCache = cache.withPrefix('users').withCodec(utf8);

  /// Get data form cache
  String userinfo = await userCache['peter-pan'].get();
  print(userinfo);

  /// Put data into cache
  await userCache['winnie'].set('Like honey');

  await cacheProvider.close();
}

Development #

To test the redis CacheProvider a redis instance must be running on localhost:6379, this can be setup with:

  • docker run --rm -p 127.0.0.1:6379:6379 redis
22
likes
160
pub points
93%
popularity

Publisher

verified publishergoogle.dev

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

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

#server #caching

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

async, convert, logging, meta, retry

More

Packages that depend on neat_cache