Skip to content

nbspou/dcache

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dcache

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

Feature

  • Supports expirable Cache, LFU, LRU.
  • Support eviction
  • Automatically load cache if it doesn't exists. (Optional)
  • Async loading of expirate value

Example

Simple use case

import 'package:dcache/dcache.dart';

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

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

Loading function

import 'package:dcache/dcache.dart';

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

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

Author

Kevin PLATEL

Releases

No releases published

Packages

No packages published

Languages

  • Dart 100.0%