BufferedStorageStrategy class

Buffered storage strategy — wraps any StorageStrategy with two optimizations:

  1. Write Buffer: Accumulates writes in RAM, flushing to disk only when commit() is called or the buffer exceeds maxPendingBytes.
  2. Write Coalescing: Merges adjacent writes into a single I/O operation, turning 10k individual writes into ~10 large sequential writes.

This is the primary reason FastDB should be 10x faster on bulk inserts.

Implemented types

Constructors

BufferedStorageStrategy(StorageStrategy _inner, {int maxPendingBytes = 256 * 1024})

Properties

hashCode int
The hash code for this object.
no setterinherited
maxPendingBytes int
final
needsExplicitFlush bool
If false, flush is a no-op and all writes are immediately visible (i.e. the underlying medium is RAM). Hot paths can skip awaiting flush and calling flush on every write when this is false.
no setteroverride
pendingBytes int
no setter
pendingWrites int
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
size Future<int>
Returns the current size of the storage in bytes.
no setteroverride
sizeSync int?
If non-null, the current byte length of the storage without awaiting. Implementations where writes are synchronous (e.g. MemoryStorageStrategy) override this to avoid a microtask bounce in hot paths.
no setteroverride

Methods

close() Future<void>
Closes the storage.
override
commit() Future<void>
Commits all buffered writes to the underlying storage in a single pass. Uses write coalescing: merges overlapping/adjacent writes into one I/O call.
flush() Future<void>
Flushes any pending writes to the physical storage.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
open() Future<void>
Opens the storage.
override
read(int offset, int sz) Future<Uint8List>
Reads a block of data at the given offset with size.
override
readSync(int offset, int size) Uint8List?
Synchronous read. Returns null if the implementation requires async I/O. Callers must fall back to read when this returns null.
override
toString() String
A string representation of this object.
inherited
truncate(int size) Future<void>
Truncates the storage to size bytes. Used by WAL checkpoint to clear the WAL file.
override
write(int offset, Uint8List data) Future<void>
Buffers a write. Actual disk I/O is deferred until commit().
override
writeSync(int offset, Uint8List data) bool
Synchronous write. Returns true if the write was performed inline (no I/O scheduling needed), false if the caller must fall back to the async write. Implementations that can guarantee a synchronous, infallible write (e.g. MemoryStorageStrategy) override this.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited