public synchronized void put ( Key key , Value value ) { long valueSize = value . getSize ( ) ; if ( maxSizeBytes == 0 || maxSizeEntries == 0 || valueSize * 2 > maxSizeBytes ) { // Just destroy the value if cache is disabled or if entry would consume more than a half of // the cache evictValue ( value ) ; return ; } currentSize += valueSize ; Value prev = cache . put ( key , value ) ; if ( prev == null ) { return ; } // This should be a rare case currentSize -= prev . getSize ( ) ; if ( prev != value ) { evictValue ( prev ) ; } }
Returns given value to the cache .