public MapMaker expiration ( long duration , TimeUnit unit ) { if ( expirationNanos != 0 ) { throw new IllegalStateException ( "expiration time of " + expirationNanos + " ns was already set" ) ; } if ( duration <= 0 ) { throw new IllegalArgumentException ( "invalid duration: " + duration ) ; } this . expirationNanos = unit . toNanos ( duration ) ; useCustomMap = true ; return this ; }
Specifies that each entry should be automatically removed from the map once a fixed duration has passed since the entry s creation .