Skip to content

Instantly share code, notes, and snippets.

@mono0926
Last active September 30, 2022 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mono0926/385db52381c92807f74d38078c54e822 to your computer and use it in GitHub Desktop.
Save mono0926/385db52381c92807f74d38078c54e822 to your computer and use it in GitHub Desktop.
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