code: public QueryableIndex cache(String dataSource, Iterable<InputRow> loader, IncrementalIndexSchema indexSchema)
              throws IOException {
          IncrementalIndex<?> incIndex = new OnheapIncrementalIndex(indexSchema, true, Integer.MAX_VALUE);
  
          for (InputRow row : loader) {
              incIndex.add(row);
          }
          String tmpDir = System.getProperty("druid.segment.dir");
          if (tmpDir == null) {
              tmpDir = System.getProperty("java.io.tmpdir") + File.separator + "druid-tmp-index-";
          }
          File tmpIndexDir = new File(tmpDir + loader.hashCode());
          IndexIO indexIO = new IndexIO(new DefaultObjectMapper(), new ColumnConfig() {
              @Override
              public int columnCacheSizeBytes() {
                  return 0;
              }
          });
          if (OSCheck.isWindows()) {
              new SlowIndexMerger(new DefaultObjectMapper(), indexIO).persist(incIndex, tmpIndexDir, new IndexSpec());
          } else {
              new IndexMerger(new DefaultObjectMapper(), indexIO).persist(incIndex, tmpIndexDir, new IndexSpec());
          }
          this.indexMap.put(dataSource, indexIO.loadIndex(tmpIndexDir));
          return this.indexMap.get(dataSource);
      }
docs: Builds and caches a QueryableIndex from an Iterable by building, persisting and reloading an IncrementalIndex
  
  @param dataSource  Key to store the index under
  @param loader      Iterable&lt;InputRow&gt; object to read data rows from
  @param indexSchema Schema of the index
  @return QueryableIndex that was cached
  @throws IOException