cacher 0.2.1 copy "cacher: ^0.2.1" to clipboard
cacher: ^0.2.1 copied to clipboard

Implementations of common cache replacement algorithms. Includes LRU, TLRU, LFU.

This is a modification of https://github.com/platelk/dcache, licensed under the MIT License.

Cacher #

Cacher is a simple library to implement application caching in dart inspired by gcache

Features #

Example #

Simple use case #

import 'package:cacher/cacher.dart';

void main() {
  Cache c = SimpleCache(storage: SimpleStorage(20));

  c.set("key", 42);
  print(c.get("key")); // 42
  print(c.containsKey("unknown_key")); // false
  print(c.get("unknown_key")); // null
}

Add logic on eviction. #

import 'package:cacher/cacher.dart';

void main() {
  Cache c = SimpleCache<Key, Disposable>(
      storage: SimpleStorage(20),
      onEvict: (key, value) {
        value.dispose();
      });
}

Loading function #

import 'package:cacher/cacher.dart';

void main() {
  Cache c = SimpleCache<int, int>(
    storage: SimpleStorage(20),
  )..loader = (key, oldValue) => key * 10;

  print(c.get(4)); // 40
  print(c.get(5)); // 50
  print(c.containsKey(6)); // false
}

Authors #

Kevin PLATEL

Harpreet Sangar

3
likes
160
pub points
42%
popularity

Publisher

unverified uploader

Implementations of common cache replacement algorithms. Includes LRU, TLRU, LFU.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

More

Packages that depend on cacher