This is a modification of https://github.com/platelk/dcache, licensed under the MIT License.
Cacher is a simple library to implement application caching in dart
inspired by gcache
- Supports expirable Cache, Least Frequently Used, Least recently used, Time aware least recently used.
- Supports eviction.
- Async loading of expired value.
- Automatically load cache if it doesn't exists. (Optional)
- Callback for evicted items to perform cleanup (Optional)
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
}
import 'package:cacher/cacher.dart';
void main() {
Cache c = SimpleCache<Key, Disposable>(
storage: SimpleStorage(20),
onEvict: (key, value) {
value.dispose();
});
}
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
}
Kevin PLATEL
- mail : [email protected]
- github : https://github.com/platelk
- twitter : https://twitter.com/kevinplatel
Harpreet Sangar
- mail : [email protected]
- github : https://github.com/happy-san