@ SuppressWarnings ( "unchecked" ) public boolean containsKey ( Object key ) { synchronized ( this ) { //WeakReference ref; SoftReference ref ; V item ; if ( ! cache . containsKey ( key ) ) { return false ; } ref = cache . get ( key ) ; item = ( V ) ref . get ( ) ; if ( item == null ) { return false ; } if ( item instanceof CachedItem ) { CachedItem ci = ( CachedItem ) item ; if ( ! ci . isValidForCache ( ) ) { remove ( key ) ; return false ; } } return true ; } }
This method will verify both that the key exists and the value is currently value for the cache .