Class TinyLfuBlockCache
- java.lang.Object
-
- org.apache.accumulo.core.file.blockfile.cache.tinylfu.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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.accumulo.core.spi.cache.BlockCache
BlockCache.Loader, BlockCache.Stats
-
-
Constructor Summary
Constructors Constructor Description TinyLfuBlockCache(BlockCacheManager.Configuration conf, CacheType type)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CacheEntry
cacheBlock(String blockName, byte[] buffer)
Add block to cache.CacheEntry
getBlock(String blockName)
Fetch block from cache.CacheEntry
getBlock(String blockName, BlockCache.Loader loader)
This method allows a cache to prevent concurrent loads of the same block.long
getMaxHeapSize()
Get the maximum amount of on heap memory this cache will use.long
getMaxSize()
Get the maximum size of this cache.BlockCache.Stats
getStats()
Get the statistics of this cache.
-
-
-
Constructor Detail
-
TinyLfuBlockCache
public TinyLfuBlockCache(BlockCacheManager.Configuration conf, CacheType type)
-
-
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 interfaceBlockCache
-
getMaxSize
public long getMaxSize()
Description copied from interface:BlockCache
Get the maximum size of this cache.- Specified by:
getMaxSize
in interfaceBlockCache
- Returns:
- max size in bytes
-
getBlock
public CacheEntry getBlock(String blockName)
Description copied from interface:BlockCache
Fetch block from cache.- Specified by:
getBlock
in interfaceBlockCache
- 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 interfaceBlockCache
- Parameters:
blockName
- Zero-based file block number.buffer
- The block contents wrapped in a ByteBuffer.
-
getStats
public BlockCache.Stats getStats()
Description copied from interface:BlockCache
Get the statistics of this cache.- Specified by:
getStats
in interfaceBlockCache
- Returns:
- statistics
-
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 interfaceBlockCache
- Parameters:
blockName
- Block name to fetchloader
- 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.
-
-