LruCache<K, V> class
LRU (Least Recently Used) 缓存实现
用于限制内存中缓存的数据量,自动淘汰最久未使用的数据。 使用 LinkedHashMap 实现 O(1) 的访问顺序更新。
使用示例:
final cache = LruCache<String, UserEntity>(maxSize: 100);
cache.put('user_1', user);
final user = cache.get('user_1');
Properties
-
entries
→ Iterable<
MapEntry< K, V> > -
获取所有缓存条目
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
-
keys
→ Iterable<
K> -
获取所有缓存的键
no setter
- length → int
-
获取当前缓存大小
no setter
- maxSize → int
-
最大缓存数量
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
values
→ Iterable<
V> -
获取所有缓存的值
no setter
Methods
-
clear(
) → void - 清空缓存
-
containsKey(
K key) → bool - 检查是否包含 key
-
evictCount(
int count) → void - 淘汰多个最久未使用的数据
-
evictToSize(
int targetSize) → void - 淘汰到指定大小
-
get(
K key) → V? - 获取缓存数据,同时更新访问顺序(O(1))
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
put(
K key, V value) → void - 存入缓存数据
-
putAll(
Map< K, V> entries) → void - 批量存入缓存数据
-
remove(
K key) → V? - 移除指定 key
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited