public V getValue ( long timeout , Callable < V > updater , boolean returnExpiredWhileUpdating , Object cacheRequestObject ) { if ( ! isInitialized ( ) || hasExpired ( timeout , cacheRequestObject ) ) { boolean lockAcquired = false ; try { long beforeLockingCreatedMillis = createdMillis ; if ( returnExpiredWhileUpdating ) { if ( ! writeLock . tryLock ( ) ) { if ( isInitialized ( ) ) { return getValueWhileUpdating ( cacheRequestObject ) ; } else { if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "Locking cache for update" ) ; } writeLock . lock ( ) ; } } } else { LOG . debug ( "Locking cache for update" ) ; writeLock . lock ( ) ; } lockAcquired = true ; V value ; if ( ! isInitialized ( ) || shouldUpdate ( beforeLockingCreatedMillis , cacheRequestObject ) ) { try { value = updateValue ( getValue ( ) , updater , cacheRequestObject ) ; if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "Updating cache for value [{}]" , value ) ; } setValue ( value ) ; } catch ( Exception e ) { throw new UpdateException ( e ) ; } } else { value = getValue ( ) ; resetTimestamp ( false ) ; } return value ; } finally { if ( lockAcquired ) { if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "Unlocking cache for update" ) ; } writeLock . unlock ( ) ; } } } else { return getValue ( ) ; } }
gets the current value from the entry and updates it if it s older than timeout