@ SuppressWarnings ( "unchecked" ) protected boolean triggerRefreshIfNeeded ( final Element e ) { if ( refreshAheadNeeded ( e . getLastAccessTime ( ) , e . getCreationTime ( ) , e . getExpirationTime ( ) ) ) { // to apply a simple and not strict concurrency locking final long signature = Thread . currentThread ( ) . getId ( ) * 1000000L + ( System . currentTimeMillis ( ) % 1000000L ) ; if ( e . getVersion ( ) == 1 ) { // 1 is the default value of version field e . setVersion ( signature ) ; if ( e . getVersion ( ) == signature ) { // double check threadPool . execute ( new Runnable ( ) { public void run ( ) { if ( e . getVersion ( ) == signature ) { // triple check try { V newValue = getDirectly ( ( K ) e . getObjectKey ( ) ) ; if ( newValue == null ) { cache . remove ( e . getObjectKey ( ) ) ; } else { cache . put ( new Element ( ( K ) e . getObjectKey ( ) , newValue ) ) ; } } catch ( Exception ex ) { logger . warn ( "Failed to update the value associated with specified key '{}' in cache '{}'" , e . getObjectKey ( ) , cache . getName ( ) , ex ) ; } } } } ) ; return true ; } } } return false ; }
Trigger refresh if it is needed