https://github.com/happy-san/dart-cacher
Implementations of common cache replacement algorithms in Dart.
https://github.com/happy-san/dart-cacher
cache dart lfu-cache lru-cache tlru-cache
Last synced: 9 months ago
JSON representation
Implementations of common cache replacement algorithms in Dart.
- Host: GitHub
- URL: https://github.com/happy-san/dart-cacher
- Owner: happy-san
- License: other
- Created: 2022-11-06T05:15:29.000Z (over 3 years ago)
- Default Branch: trunk
- Last Pushed: 2023-11-05T09:43:51.000Z (over 2 years ago)
- Last Synced: 2025-04-07T03:22:18.579Z (about 1 year ago)
- Topics: cache, dart, lfu-cache, lru-cache, tlru-cache
- Language: Dart
- Homepage: https://pub.dev/packages/cacher
- Size: 61.5 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
> 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](https://github.com/bluele/gcache)
## Features
* Supports expirable Cache, [Least Frequently Used](https://en.wikipedia.org/wiki/Least_frequently_used), [Least recently used](https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU), [Time aware least recently used](https://en.wikipedia.org/wiki/Cache_replacement_policies#Time_aware_least_recently_used_(TLRU)).
* Supports eviction.
* Async loading of expired value.
* Automatically load cache if it doesn't exists. (Optional)
* Callback for evicted items to perform cleanup (Optional)
## Example
### Simple use case
```dart
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.
```dart
import 'package:cacher/cacher.dart';
void main() {
Cache c = SimpleCache(
storage: SimpleStorage(20),
onEvict: (key, value) {
value.dispose();
});
}
```
### Loading function
```dart
import 'package:cacher/cacher.dart';
void main() {
Cache c = SimpleCache(
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*
* mail :
* github :
* twitter :
*Harpreet Sangar*
* mail :
* github :