Is it possible to read my own writes within the same transaction, if that transaction has not yet been committed?
1 Answers
Create a CacheManager
wrapper atop BadgerDB's read and write transactions to manage an in-memory cache for better consistency:
Initialization: Set up
CacheManager
with an empty cache, maximum cache size, and a linked BadgerDB instance.Custom Read: Implement a read function that checks the in-memory cache first. If the key is cached, return its value; otherwise, read from BadgerDB. This ensures recent data accessibility within transactions.
Custom Write: Create a write function that updates the cache with new key-value pairs. If the cache exceeds the size limit, initiate a batch flush to store cached entries on disk.
Cache Control: Monitor cache size during writes. Exceeding the limit triggers a batch flush for memory efficiency and consistent storage.
With CacheManager
, you seamlessly blend in-memory caching and BadgerDB, enabling read-your-own-writes within transactions while maintaining data coherence and efficiency.

- 358
- 1
- 10