dcache 0.4.0 copy "dcache: ^0.4.0" to clipboard
dcache: ^0.4.0 copied to clipboard

Provide a simple dart cache library usable on web, flutter and server side

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
  • Callback for evicted items to perform cleanup (Optional)

Example #

Simple use case #

import 'package:dcache/dcache.dart';

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

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

Evict items #

import 'package:dcache/dcache.dart';

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

    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(20))
    ..loader = (key, oldValue) => key*10
  ;

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

Author #

Kevin PLATEL

11
likes
125
pub points
84%
popularity

Publisher

unverified uploader

Provide a simple dart cache library usable on web, flutter and server side

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

meta

More

Packages that depend on dcache