put method
void
put(
- K key,
- V value
Implementation
void put(K key, V value) {
if (_cacheMap.length >= capacity) {
// 容量满了,使用策略移除旧条目
final keyToEvict = _policy.evict(_cacheMap);
if (keyToEvict != null) {
_cacheMap.remove(keyToEvict);
}
}
_policy.recordInsertion(key);
_cacheMap[key] = CacheEntry(value);
}