protected synchronized boolean put ( K k , E object , long ttl , boolean eternal ) { // Check the key map first if ( exists ( k ) ) { TTLObject < K , E > ttlObject = getTTLObject ( k ) ; Key < K > key = keys . get ( k ) ; key . setTime ( System . currentTimeMillis ( ) ) ; ttlObject . setEternal ( eternal ) ; ttlObject . extendLife ( ttl ) ; ttlObject . setObject ( object ) ; if ( eventListener != null ) { eventListener . onPut ( object ) ; } return true ; } else { TTLObject < K , E > t = new TTLObject < K , E > ( object , k , ttl ) ; t . setEternal ( eternal ) ; long addedSize = object . getSizeInBytes ( ) ; long newSize = currentSizeInBytes + addedSize ; boolean oversize = false ; oversize = ( hardByteLimit && maxCapacityBytes > 0 && newSize > maxCapacityBytes ) ; if ( ! oversize ) { Key < K > key = new Key < K > ( k , System . currentTimeMillis ( ) ) ; keys . put ( k , key ) ; objects . put ( key , t ) ; t . getObject ( ) . onPut ( k ) ; // Increment size currentSizeInBytes = newSize ; if ( eventListener != null ) { eventListener . onPut ( object ) ; } return true ; } } return false ; }
Adds an object to cache with the given Time To Live in milliseconds