001/* 002 * Copyright (C) 2011 The Guava Authors 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 005 * in compliance with the License. You may obtain a copy of the License at 006 * 007 * http://www.apache.org/licenses/LICENSE-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, software distributed under the License 010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 011 * or implied. See the License for the specific language governing permissions and limitations under 012 * the License. 013 */ 014 015package com.google.common.cache; 016 017import com.google.common.annotations.GwtCompatible; 018 019/** 020 * An object that can receive a notification when an entry is removed from a cache. The removal 021 * resulting in notification could have occurred to an entry being manually removed or replaced, or 022 * due to eviction resulting from timed expiration, exceeding a maximum size, or garbage collection. 023 * 024 * <p>An instance may be called concurrently by multiple threads to process different entries. 025 * Implementations of this interface should avoid performing blocking calls or synchronizing on 026 * shared resources. 027 * 028 * @param <K> the most general type of keys this listener can listen for; for example {@code Object} 029 * if any key is acceptable 030 * @param <V> the most general type of values this listener can listen for; for example {@code 031 * Object} if any key is acceptable 032 * @author Charles Fry 033 * @since 10.0 034 */ 035@GwtCompatible 036@FunctionalInterface 037@ElementTypesAreNonnullByDefault 038public interface RemovalListener<K, V> { 039 /** 040 * Notifies the listener that a removal occurred at some point in the past. 041 * 042 * <p>This does not always signify that the key is now absent from the cache, as it may have 043 * already been re-added. 044 */ 045 // Technically should accept RemovalNotification<? extends K, ? extends V>, but because 046 // RemovalNotification is guaranteed covariant, let's make users' lives simpler. 047 void onRemoval(RemovalNotification<K, V> notification); 048}