Skip to main content
RocksDB uses caches to improve read performance by storing frequently accessed data blocks in memory. The Cache API provides several implementations including LRU and HyperClockCache.

Cache Types

BlockCache vs RowCache

BlockCache stores uncompressed data blocks from SST files. RowCache stores entire key-value pairs for faster point lookups.

Creating a Cache

LRUCacheOptions

size_t
Total capacity of the cache in bytes.
int
Cache is sharded into 2^num_shard_bits shards by hash of key. If negative, a good default is chosen automatically.
bool
If true, Insert() fails when there is not enough capacity. If false, Insert() never fails.
double
Ratio of cache reserved for high-priority entries (0 to 1). 0.5 means non-high-priority entries use midpoint insertion.

MakeSharedCache

Creates an LRU cache with the configured options.
std::shared_ptr<Cache>
Returns a shared pointer to the created cache.

HyperClockCacheOptions

size_t
Estimated average charge per entry. 0 uses a dynamic-growing table variant. Non-zero uses the most efficient fixed-size variant.
int
Controls CPU vs memory tradeoff under stress. Higher values allow slightly more memory overhead to keep eviction performant.

Legacy Cache Creation Functions

NewLRUCache

Deprecated wrapper function. Use LRUCacheOptions::MakeSharedCache() instead.

Secondary Cache

CompressedSecondaryCacheOptions

CompressionType
Compression method for secondary cache entries.
CacheEntryRoleSet
Types of entries that should not be compressed. Filter blocks are non-compressible by default.

MakeSharedSecondaryCache

Creates a compressed secondary cache with the configured options.

Tiered Cache

TieredCacheOptions

size_t
Total memory budget divided between primary and compressed secondary cache.
double
Ratio of total capacity allocated to compressed secondary cache (0.0 to 1.0).

NewTieredCache

Creates a 2-tier cache with primary uncompressed and secondary compressed tiers.

UpdateTieredCache

Dynamically updates tiered cache parameters.

Cache Entry Roles

Classifications of cache entries for monitoring and policy decisions.

Cache Metadata Charging

CacheMetadataChargePolicy
Only entry data counts against capacity.
CacheMetadataChargePolicy
Both entry data and cache overhead count against capacity. Default.

Example: LRU Cache

Example: HyperClockCache

Example: Tiered Cache

Cache Statistics

Get cache statistics using:

See Also