@ Override @ SuppressWarnings ( "unchecked" ) public < T > T get ( final Object key , final Class < T > type ) { if ( ! cache . isEnabled ( ) ) { LOGGER . warn ( "Cache {} is disabled. Cannot get {} from cache" , cache . getName ( ) , key ) ; return null ; } Object value = getValue ( key ) ; if ( value == null ) { LOGGER . info ( "Cache miss. Get by key {} and type {} from cache {}" , new Object [ ] { key , type , cache . getName ( ) } ) ; return null ; } if ( value instanceof PertinentNegativeNull ) { return null ; } if ( type != null && ! type . isInstance ( value ) ) { // in such case default Spring back end for EhCache throws IllegalStateException which interrupts // intercepted method invocation String msg = "Cached value is not of required type [" + type . getName ( ) + "]: " + value ; LOGGER . error ( msg , new IllegalStateException ( msg ) ) ; return null ; } LOGGER . info ( "Cache hit. Get by key {} and type {} from cache {} value '{}'" , new Object [ ] { key , type , cache . getName ( ) , value } ) ; return ( T ) value ; }
Required by Spring 4 . 0