Class TinyLfuBlockCache

  • All Implemented Interfaces:
    BlockCache

    public final class TinyLfuBlockCache
    extends Object
    implements BlockCache
    A block cache that is memory bounded using the W-TinyLFU eviction algorithm. This implementation delegates to a Caffeine cache to provide concurrent O(1) read and write operations.
    • Method Detail

      • getMaxHeapSize

        public long getMaxHeapSize()
        Description copied from interface: BlockCache
        Get the maximum amount of on heap memory this cache will use.
        Specified by:
        getMaxHeapSize in interface BlockCache
      • getMaxSize

        public long getMaxSize()
        Description copied from interface: BlockCache
        Get the maximum size of this cache.
        Specified by:
        getMaxSize in interface BlockCache
        Returns:
        max size in bytes
      • getBlock

        public CacheEntry getBlock​(String blockName)
        Description copied from interface: BlockCache
        Fetch block from cache.
        Specified by:
        getBlock in interface BlockCache
        Parameters:
        blockName - Block name to fetch.
        Returns:
        Block or null if block is not in the cache.
      • cacheBlock

        public CacheEntry cacheBlock​(String blockName,
                                     byte[] buffer)
        Description copied from interface: BlockCache
        Add block to cache.
        Specified by:
        cacheBlock in interface BlockCache
        Parameters:
        blockName - Zero-based file block number.
        buffer - The block contents wrapped in a ByteBuffer.
      • getBlock

        public CacheEntry getBlock​(String blockName,
                                   BlockCache.Loader loader)
        Description copied from interface: BlockCache
        This method allows a cache to prevent concurrent loads of the same block. However a cache implementation is not required to prevent concurrent loads. SynchronousLoadingBlockCache is an abstract class that a cache can extent which does prevent concurrent loading of the same block.
        Specified by:
        getBlock in interface BlockCache
        Parameters:
        blockName - Block name to fetch
        loader - If the block is not present in the cache, the loader can be called to load it.
        Returns:
        Block or null if block is not in the cache or didn't load.