Last active
September 30, 2022 05:01
-
-
Save mono0926/385db52381c92807f74d38078c54e822 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:quiver/collection.dart'; | |
void main() { | |
// maximumSizeのデフォルトは100 | |
final cache = LruMap<String, int>(maximumSize: 3); | |
cache['a'] = 1; | |
print(cache['a']); // 1 | |
cache['b'] = 2; | |
print(cache['a']); // 1 | |
// bがaより最近使った扱いされるように触る | |
cache['b']; | |
cache['c'] = 3; | |
cache['d'] = 4; | |
// 直近触った b, c, d の3つがキャッシュされていて、aはキャッシュアウト👋 | |
print(cache['a']); // null | |
print(cache['b']); // 2 | |
print(cache['c']); // 3 | |
print(cache['d']); // 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment