mocha 0.0.2

mocha

Mocha is a simple caching library for Dart.

Features

  • Size-based eviction
  • Time-based expiration (since last write)
  • Asynchronously refresh values
  • Automatic asynchronous loading of values into the cache
  • Manually...
    • Evict/invalidate values
    • Populate the cache

Usage

A simple usage example:

import 'dart:async';
import 'package:mocha/mocha.dart';

Future<String> expensiveOperation(int key) async {
  // pretend this is takes time to calculate
  var sq = key * key;
  return '$key^2 = $sq';
}

main() async {
  var cache = new LoadingCache<int, String>(
    expensiveOperation,
    maximumSize: 10,
    expiresAfterWrite: const Duration(minutes: 1)
  );

  print(await cache.get(4));
}

Features and bugs

Please file feature requests and bugs at the issue tracker.

Changelog

0.0.2

  • Improved expiration (no timers)
  • Refresher -> Callable

0.0.1

  • Initial version.

1. Depend on it

Add this to your package's pubspec.yaml file:

dependencies:
  mocha: "^0.0.2"

2. Install it

You can install packages from the command line:

$ pub get

Alternatively, your editor might support 'pub get'. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:mocha/mocha.dart';

About

A simple caching library.

Author

Email keenan@keenant.com Keenan Thompson

Homepage

github.com/thekeenant/mocha

Documentation

www.dartdocs.org/documentation/mocha/0.0.2/

Source code (hyperlinked)

www.crossdart.info/p/mocha/0.0.2/

Uploader

keenan@keenant.com

Share