Skip to content

happy-san/dart-cacher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Implementations of common cache replacement algorithms in Dart.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages