put method
void
put(
- K key,
- V value
Inserts or updates the key with value.
If the cache exceeds capacity, evicts the least recently used entry.
Implementation
void put(K key, V value) {
if (_cache.containsKey(key)) {
_cache.remove(key);
}
if (_cache.length >= capacity) {
_cache.remove(_cache.keys.first);
}
_cache[key] = value;
}