Skip to content

Commit cd4a4f3

Browse files
committed
Improve removeKey
1 parent dccf3c1 commit cd4a4f3

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

src/main/java/com/thealgorithms/datastructures/caches/FIFOCache.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ public void put(K key, V value, long ttlMillis) {
201201
* Removes all expired entries from the cache.
202202
*
203203
* <p>This method iterates through the list of cached keys and checks each associated
204-
* entry for expiration. Expired entries are removed from both the key tracking list
205-
* and the cache map. For each eviction, the eviction listener is notified.
204+
* entry for expiration. Expired entries are removed the cache map. For each eviction,
205+
* the eviction listener is notified.
206206
*/
207207
private int evictExpired() {
208208
int count = 0;
@@ -223,18 +223,17 @@ private int evictExpired() {
223223
/**
224224
* Removes the specified key and its associated entry from the cache.
225225
*
226-
* <p>This method deletes the key from both the cache map and the key tracking list.
227-
*
228-
* @param key the key to remove from the cache
226+
* @param key the key to remove from the cache;
227+
* @return the value associated with the key; or {@code null} if no such key exists
229228
*/
230229
public V removeKey(K key) {
231230
if (key == null) {
232231
throw new IllegalArgumentException("Key cannot be null");
233232
}
234233
CacheEntry<V> entry = cache.remove(key);
235234

235+
// No such key in cache
236236
if (entry == null) {
237-
notifyEviction(key, null);
238237
return null;
239238
}
240239

0 commit comments

Comments
 (0)