FileMemoryStore class final
A persistent MemoryStore that stores one JSON file per record in
a directory: <root>/<id>.json.
Guarantees
A torn file is never read as a record: writes go to a uniquely
named .tmp file, are flushed, and are atomically renamed over the
record. Reads never mutate the directory. A lone .tmp reads as
absent — it was never acknowledged, so it is not a record. Stale
.tmp files are swept on list. Concurrent processes cannot
clobber each other's temp files because each temp name is unique;
compare-and-swap is in-process only
(crossProcessCas: false), which the class claims and no more.
Errors
Every failure is a typed error: unreadable bytes, invalid UTF-8,
malformed JSON, an unknown schema or a bad id are MemoryCorrupt;
filesystem failures (including directory creation) are
MemoryIoException; a lost CAS race is MemoryConflict; calls
after close are StateError.
- Implemented types
Constructors
- FileMemoryStore.directory(Directory root, {MemoryClock clock = const SystemMemoryClock()})
-
Opens a directory-based store where each record is stored as
<root>/<id>.json.
Properties
- capabilities → MemoryStoreCapabilities
-
What this backend can guarantee.
no setteroverride
- hashCode → int
-
The hash code for this object.
no setterinherited
- name → String
-
The backend's display name.
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
close(
) → Future< void> -
Closes the store (C6). Idempotent: a second close returns the
first close's future. Late calls throw
StateError.override -
list(
) → Future< List< String> > -
Ids this store currently holds, as a settled snapshot excluding
expired rows (C3, C7). Order is unspecified.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
purgeExpired(
{DateTime? now}) → Future< int> -
Removes every expired row and returns how many were removed.
override
-
read(
String id) → Future< MemoryEnvelope?> -
Reads the envelope stored under
id, ornullwhen absent or expired (C1, C3).override -
remove(
String id, {MemoryVersion? ifVersion}) → Future< void> -
Deletes the durable record for
id.override -
toString(
) → String -
A string representation of this object.
inherited
-
write(
MemoryDraft draft, {MemoryVersion? expected}) → Future< MemoryEnvelope> -
Atomically installs
draftunder the rules of MemoryCas.decide and returns the committed envelope (C2).override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited