001 /* 002 * Copyright (C) 2011 The Guava Authors 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 package com.google.common.cache; 018 019 import com.google.common.annotations.Beta; 020 021 import java.util.Iterator; 022 import java.util.Map; 023 import java.util.concurrent.ConcurrentMap; 024 025 /** 026 * The reason why a cached entry was removed. 027 * 028 * @author Charles Fry 029 * @since 10.0 030 */ 031 @Beta 032 public enum RemovalCause { 033 /** 034 * The entry was manually removed by the user. This can result from the user invoking {@link 035 * Cache#invalidate}, {@link Map#remove}, {@link ConcurrentMap#remove}, or {@link 036 * Iterator#remove}. 037 */ 038 EXPLICIT { 039 @Override 040 boolean wasEvicted() { 041 return false; 042 } 043 }, 044 045 /** 046 * The entry itself was not actually removed, but its value was replaced by the user. This can 047 * result from the user invoking {@link Map#put}, {@link Map#putAll}, 048 * {@link ConcurrentMap#replace(Object, Object)}, or 049 * {@link ConcurrentMap#replace(Object, Object, Object)}. 050 */ 051 REPLACED { 052 @Override 053 boolean wasEvicted() { 054 return false; 055 } 056 }, 057 058 /** 059 * The entry was removed automatically because its key or value was garbage-collected. This 060 * can occur when using {@link CacheBuilder#weakKeys}, {@link CacheBuilder#weakValues}, or 061 * {@link CacheBuilder#softValues}. 062 */ 063 COLLECTED { 064 @Override 065 boolean wasEvicted() { 066 return true; 067 } 068 }, 069 070 /** 071 * The entry's expiration timestamp has passed. This can occur when using {@link 072 * CacheBuilder#expireAfterWrite} or {@link CacheBuilder#expireAfterAccess}. 073 */ 074 EXPIRED { 075 @Override 076 boolean wasEvicted() { 077 return true; 078 } 079 }, 080 081 /** 082 * The entry was evicted due to size constraints. This can occur when using {@link 083 * CacheBuilder#maximumSize}. 084 */ 085 SIZE { 086 @Override 087 boolean wasEvicted() { 088 return true; 089 } 090 }; 091 092 /** 093 * Returns {@code true} if there was an automatic removal due to eviction (the cause is neither 094 * {@link #EXPLICIT} nor {@link #REPLACED}). 095 */ 096 abstract boolean wasEvicted(); 097 }