private void doCacheOnWrite(long offset) {
    cacheConf.getBlockCache().ifPresent(cache -> {
      HFileBlock cacheFormatBlock = blockWriter.getBlockForCaching(cacheConf);
      BlockCacheKey key = buildCacheBlockKey(offset, cacheFormatBlock.getBlockType());
      try {
        cache.cacheBlock(key, cacheFormatBlock, cacheConf.isInMemory(), true);
      } finally {
        // refCnt will auto increase when block add to Cache, see RAMCache#putIfAbsent
        cacheFormatBlock.release();
      }
    });
  }
Caches the last written HFile block.
@param offset the offset of the block we want to cache. Used to determine the cache key.
hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileWriterImpl.java