0

Is it possible to read my own writes within the same transaction, if that transaction has not yet been committed?

Han
  • 1,283
  • 11
  • 25

1 Answers1

-1

Create a CacheManager wrapper atop BadgerDB's read and write transactions to manage an in-memory cache for better consistency:

  1. Initialization: Set up CacheManager with an empty cache, maximum cache size, and a linked BadgerDB instance.

  2. 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.

  3. 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.

  4. 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.

Vishal Jangid
  • 358
  • 1
  • 10