PagedFile class

Bounded LRU page cache + undo journal over a fixed-page-size file.

Not thread-safe on its own — callers must serialise mutations through the existing AsyncRwLock (the executor's writer lock already does this).

Properties

cacheCapacity → int
Maximum number of resident pages. Must be at least 1. When the cache is full and a new page is faulted in, the least-recently-used clean page is evicted; if every cached page is dirty we flush a partial commit (writing dirty pages out under the journal) so we can keep going.
final
cachedPageCount → int
Number of pages currently held in the in-memory cache.
no setter
hashCode → int
The hash code for this object.
no setterinherited
hasUncommittedChanges → bool
True if the cache holds dirty pages waiting for commit.
no setter
pageCount → int
Number of pages currently allocated in the data file.
no setter
pageSize → int
Bytes per page. Must be a power of two, at least 512.
final
path → String
Path to the underlying data file.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

abandonForCrashTest() → Future<void>
Test-only. Close the data and journal file handles WITHOUT committing dirty pages or deleting the journal. This is what a real process crash would look like to the next PagedFile.open: the journal stays on disk, recording the pre-transaction image of every page that was modified, and recovery rolls those pages back.
allocatePage() → Future<int>
Allocate a new page at the end of the file. Returns its page number. The page is zero-filled, cached, and marked dirty.
close() → Future<void>
Flush all caches and close file handles. Implicitly commits any pending dirty pages.
commit() → Future<void>
Commit pending dirty pages to disk and finalise the transaction.
getForWrite(int pageNo) → Future<Uint8List>
Read page pageNo for modification. The returned buffer is mutable; the page is automatically journaled (once per transaction) and marked dirty. commit will flush it to disk.
markDirty(int pageNo) → Future<void>
Mark an already-mutated cached page dirty. Prefer getForWrite when possible — it captures the undo image automatically.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
read(int pageNo) → Future<Uint8List>
Read page pageNo. The returned buffer is the live cache copy — callers MUST NOT mutate it without calling markDirty; if you want to modify a page, use getForWrite instead.
rollback() → Future<void>
Discard pending dirty pages without writing them. The journal is replayed in-place to restore any pages already flushed.
toString() → String
A string representation of this object.
inherited

Operators

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

Static Methods

open(String path, {int pageSize = 4096, int cacheCapacity = 64}) → Future<PagedFile>
Open (or create) a paged file.