Skip to main content

dox_cache 3.2.2 copy "dox_cache: ^3.2.2" to clipboard
dox_cache: ^3.2.2 copied to clipboard

Cache for Dart and the Dox framework. Memory, file and Redis drivers, TTL, locks, tags and remember helpers.

dox_cache #

Cache for Dart with memory, file and Redis drivers.

pub package license: MIT

Part of Dox, a web backend framework for Dart. Source code: github.com/dartondox/dox.

Install #

dart pub add dox_cache

To see what is ready and what may still change, read Status and roadmap.

Use it #

import 'package:dox_cache/dox_cache.dart';

void main() async {
  CacheManager cache = CacheManager(CacheConfig(
    defaultStore: 'memory',
    stores: <String, Map<String, dynamic>>{
      'memory': <String, dynamic>{'driver': 'memory', 'max_size': 1000},
      'file': <String, dynamic>{'driver': 'file', 'path': 'storage/cache'},
      'redis': <String, dynamic>{'driver': 'redis', 'host': '127.0.0.1', 'prefix': 'app:'},
    },
  ));

  CacheStore store = cache.store(); // the default store
  await store.put('a', 1, Duration(minutes: 5));
  print(await store.get('a')); // 1

  List<dynamic> posts = await store.remember('posts', Duration(minutes: 10), () async {
    return <dynamic>['first post'];
  });
  print(posts);
}

In a Dox app you do not set this up yourself. Set the stores in config/cache.dart and use Cache().

Encrypt values #

Add 'encrypt': true to a file or redis store, and pass encrypter: to CacheConfig. In a Dox app the Dox().cache encrypter uses your APP_KEY. On Redis, plain ints stay plain, so increment still works.

Features #

  • Drivers: memory (with an optional LRU size limit), file, redis and null.
  • get, put, add, forget, many, putMany, increment, pull, remember.
  • Tags: store.tags(['users']).flush() removes only those items.
  • Atomic locks with lock(name, ttl): get(), release(), block(timeout). Memory, file and Redis.
  • A key prefix per store. Redis flush deletes only keys with the prefix.
  • Your own driver with cache.extend(name, factory).

Values must be JSON types: Map, List, String, num, bool, null. The memory store lives in one isolate. Use redis when isolates or servers must share data.

Documentation #

License #

MIT. See LICENSE.

0
likes
160
points
2.27k
downloads

Documentation

API reference

Publisher

verified publisherdartondox.dev

Weekly Downloads

Cache for Dart and the Dox framework. Memory, file and Redis drivers, TTL, locks, tags and remember helpers.

Homepage
Repository (GitHub)
View/report issues
Contributing

License

MIT (license)

Dependencies

crypto, dox_annotation, ioredis

More

Packages that depend on dox_cache