barrel_cache (barrel_docdb v1.0.0)

View Source

Shared RocksDB block cache manager

Manages a shared block cache used by all RocksDB instances. This improves memory efficiency and cache hit rates by sharing a single cache across document stores and attachment stores.

The cache is configured via application environment:

   {barrel_docdb, [
       {block_cache_size, 536870912},  %% 512MB default
       {block_cache_type, clock}       %% clock (default) or lru
   ]}

Clock cache provides better performance under concurrent load.

Summary

Functions

Get block-based table options with shared cache and bloom filter

Get block-based table options with custom settings

Get the shared cache handle

Start the cache manager

Functions

get_block_opts()

-spec get_block_opts() -> list().

Get block-based table options with shared cache and bloom filter

get_block_opts(Options)

-spec get_block_opts(map()) -> list().

Get block-based table options with custom settings

Options: - bloom_bits: Bloom filter bits per key (default: 10) - block_size: Block size in bytes (default: 4096) - cache_index_and_filter: Cache index/filter blocks (default: true)

If the cache process is not running (e.g., during standalone tests), returns options without the shared cache.

get_cache()

-spec get_cache() -> {ok, rocksdb:cache_handle()} | {error, not_started}.

Get the shared cache handle

handle_call(Request, From, State)

handle_cast(Msg, State)

handle_info(Info, State)

init(_)

start_link()

-spec start_link() -> {ok, pid()} | {error, term()}.

Start the cache manager

terminate(Reason, State)