1/* 2 * Copyright (C) 2011 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.google.common.cache; 18 19import com.google.common.annotations.Beta; 20 21import java.util.Iterator; 22import java.util.Map; 23import java.util.concurrent.ConcurrentMap; 24 25/** 26 * The reason why a cached entry was removed. 27 * 28 * @author Charles Fry 29 * @since 10.0 30 */ 31@Beta 32public enum RemovalCause { 33 /** 34 * The entry was manually removed by the user. This can result from the user invoking 35 * {@link Cache#invalidate}, {@link Cache#invalidateAll(Iterable)}, {@link Cache#invalidateAll()}, 36 * {@link Map#remove}, {@link ConcurrentMap#remove}, or {@link Iterator#remove}. 37 */ 38 EXPLICIT { 39 @Override 40 boolean wasEvicted() { 41 return false; 42 } 43 }, 44 45 /** 46 * The entry itself was not actually removed, but its value was replaced by the user. This can 47 * result from the user invoking {@link Cache#put}, {@link LoadingCache#refresh}, {@link Map#put}, 48 * {@link Map#putAll}, {@link ConcurrentMap#replace(Object, Object)}, or 49 * {@link ConcurrentMap#replace(Object, Object, Object)}. 50 */ 51 REPLACED { 52 @Override 53 boolean wasEvicted() { 54 return false; 55 } 56 }, 57 58 /** 59 * The entry was removed automatically because its key or value was garbage-collected. This 60 * can occur when using {@link CacheBuilder#weakKeys}, {@link CacheBuilder#weakValues}, or 61 * {@link CacheBuilder#softValues}. 62 */ 63 COLLECTED { 64 @Override 65 boolean wasEvicted() { 66 return true; 67 } 68 }, 69 70 /** 71 * The entry's expiration timestamp has passed. This can occur when using 72 * {@link CacheBuilder#expireAfterWrite} or {@link CacheBuilder#expireAfterAccess}. 73 */ 74 EXPIRED { 75 @Override 76 boolean wasEvicted() { 77 return true; 78 } 79 }, 80 81 /** 82 * The entry was evicted due to size constraints. This can occur when using 83 * {@link CacheBuilder#maximumSize} or {@link CacheBuilder#maximumWeight}. 84 */ 85 SIZE { 86 @Override 87 boolean wasEvicted() { 88 return true; 89 } 90 }; 91 92 /** 93 * Returns {@code true} if there was an automatic removal due to eviction (the cause is neither 94 * {@link #EXPLICIT} nor {@link #REPLACED}). 95 */ 96 abstract boolean wasEvicted(); 97} 98