thekeenant / mocha

:coffee: A caching library for Dart inspired by Guava.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

:coffee: A caching library for Dart inspired by Guava.

License:MIT License


Languages

Language:Dart 100.0%