code: func NewNRTCachingDirectory(delegate Directory, maxMergeSizeMB, maxCachedMB float64) (nrt *NRTCachingDirectory) {
  	nrt = &NRTCachingDirectory{
  		Directory:         delegate,
  		Locker:            &sync.Mutex{},
  		cache:             NewRAMDirectory(),
  		maxMergeSizeBytes: int64(maxMergeSizeMB * 1024 * 1024),
  		maxCachedBytes:    int64(maxCachedMB * 1024 * 1024),
  		uncacheLock:       &sync.Mutex{},
  	}
  	// Subclass can override this to customize logic; return true if this
  	// file should be written to the RAMDirectory.
  	nrt.doCacheWrite = func(name string, context IOContext) bool {
  		var bytes int64
  		if context.MergeInfo != nil {
  			bytes = context.MergeInfo.EstimatedMergeBytes
  		} else if context.FlushInfo != nil {
  			bytes = context.FlushInfo.EstimatedSegmentSize
  		}
  		if NRT_VERBOSE {
  			log.Printf("CACHE check merge=%v flush=%v size=%v",
  				context.MergeInfo, context.FlushInfo, bytes)
  		}
  		return name != "segments.gen" &&
  			bytes <= nrt.maxMergeSizeBytes &&
  			bytes+nrt.cache.RamBytesUsed() <= nrt.maxCachedBytes
  	}
  	return
  }
docs: /*
  We will cache a newly created output if 1) it's a flush or a merge
  and the estimated size of the merged segment is <= maxMergedSizeMB,
  and 2) the total cached bytes is <= maxCachedMB.
  */