Caching in Leveldb

Skip to first unread message

Feb 21, 2018, 4:57:18 AM2/21/18
to leveldb
How is caching implemented in LevelDB? What are block_cache and table_cache structures used for? If my code does read of old data(stored in higher levels) frequently, will it be cached for quick reads or does the control go through all the levels to search for it?

Shikhar Bharadwaj

Daniel Murphy

Feb 21, 2018, 2:44:09 PM2/21/18
The block cache is for block data, the table cache is for table metadata, which is a different file (I believe). The block cache is, by default, 8MB. It uses a sharded LRU eviction scheme and is multi-threaded. There are 16 random (based on hash) shards, and each shard is LRU. So it's combining random eviction (which is proven to be within 2* optimal or something like that), and LRU, which is pretty good for the compaction jobs. As far as I can tell it's a pretty good scheme.

See cache.h and The leveldb options should allow you to set a custom cache.

You received this message because you are subscribed to the Google Groups "leveldb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
For more options, visit
Reply all
Reply to author
0 new messages