put method
void
put(
- K key,
- V value
Puts a value in the cache If the cache is full, removes the least recently used item
Implementation
void put(K key, V value) {
if (_cache.containsKey(key)) {
// Remove the key to update its position
_cache.remove(key);
} else if (_cache.length >= _capacity) {
// Remove the first (least recently used) item
_cache.remove(_cache.keys.first);
}
_cache[key] = value;
}