Class BlockCache


  • public class BlockCache
    extends Object
    WARNING: This API is experimental and might change in incompatible ways in the next release.
    • Constructor Detail

      • BlockCache

        public BlockCache​(Metrics metrics,
                          boolean directAllocation,
                          long totalMemory)
      • BlockCache

        public BlockCache​(Metrics metrics,
                          boolean directAllocation,
                          long totalMemory,
                          int slabSize)
      • BlockCache

        public BlockCache​(Metrics metrics,
                          boolean directAllocation,
                          long totalMemory,
                          int slabSize,
                          int blockSize)
    • Method Detail

      • store

        public boolean store​(BlockCacheKey blockCacheKey,
                             int blockOffset,
                             byte[] data,
                             int offset,
                             int length)
        This is only best-effort... it's possible for false to be returned, meaning the block was not able to be cached. NOTE: blocks may not currently be updated (false will be returned if the block is already cached) The blockCacheKey is cloned before it is inserted into the map, so it may be reused by clients if desired.
        Parameters:
        blockCacheKey - the key for the block
        blockOffset - the offset within the block
        data - source data to write to the block
        offset - offset within the source data array
        length - the number of bytes to write.
        Returns:
        true if the block was cached/updated
      • fetch

        public boolean fetch​(BlockCacheKey blockCacheKey,
                             byte[] buffer,
                             int blockOffset,
                             int off,
                             int length)
        Parameters:
        blockCacheKey - the key for the block
        buffer - the target buffer for the read result
        blockOffset - offset within the block
        off - offset within the target buffer
        length - the number of bytes to read
        Returns:
        true if the block was cached and the bytes were read
      • fetch

        public boolean fetch​(BlockCacheKey blockCacheKey,
                             byte[] buffer)
      • getSize

        public int getSize()
        returns the number of elements in the cache