InMemoryReplayGuard class
A bounded, in-process ReplayGuard: a map from id to the digest accepted
under it, its retention deadline, and the response it produced.
Suitable when one process is the sole consumer for the recipient VID it
serves and losing the record on restart is acceptable.
Not suitable when the consumer is replicated: two replicas hold separate maps, so a document accepted by replica A is fresh at replica B and the effect happens twice — the exact failure item 11 exists to prevent. Replicated deployments MUST back the guard with a shared store.
When it is full. A record is dropped only once its retainUntil has
passed — never to make room. When a new id arrives and every slot holds a
record still inside its retention window, claim throws
ReplayGuardFullException, which consumeInbound answers unavailable
(retryable): the guard refuses to execute a document it could not then
remember, rather than forgetting one it promised to. Records whose window
has closed are reclaimed first. The capacity is therefore a ceiling on
distinct documents per retention window; see defaultReplayCapacity. A
document carrying an expiresAt but no issuedAt is not bounded by the
expiry horizon (it runs from issuedAt), so under a policy that does not
require issuedAt its record lives until its expiresAt.
One party's share. So that one party cannot fill the guard and hold
every slot for the length of the expiry horizon, no issuer may hold more
than a share of the capacity — a tenth by default, rounded up
(perIssuerLimit changes it). A party at its share is refused
unavailable for its own new documents; others are unaffected. The issuer
is the one consumeInbound resolved (SPEC §4.8.1) and passes to
claimFor; documents with no resolved issuer, and direct calls to claim,
share one allowance. The share is per identifier: where anyone can mint
identifiers, a party using many is limited only by the capacity.
Memory. At most capacity records, each its id, a digest and the
response cached for duplicates: roughly capacity × (largest id +
largest response) at worst.
Dart is single-threaded per isolate and none of these methods await, so claim-and-record is atomic by construction.
- Implemented types
Constructors
- InMemoryReplayGuard([int capacity = defaultReplayCapacity, int? perIssuerLimit])
-
Builds a guard retaining at most
capacityrecords.
Properties
Methods
-
claim(
String id, String digest, DateTime? retainUntil, DateTime now) → Future< ReplayVerdict> -
Claim
idfor execution on behalf of a document with identitydigest.override -
claimFor(
String? issuer, String id, String digest, DateTime? retainUntil, DateTime now) → Future< ReplayVerdict> -
ReplayGuard.claim, counting the record against
issuer.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
purgeExpired(
DateTime now) → void -
Drop every record whose
retainUntilhas passed. -
recordResponse(
String id, Map< String, dynamic> ? response) → Future<void> -
Attach the response a completed execution produced, so a later duplicate
can be answered with it per §7.2 (Disposition of a duplicate) rather than
merely absorbed in silence.
override
-
release(
String id, String digest) → Future< void> -
Release a claim whose execution is not to stand — for example a refusal the
consumer marked
retryable, where §8.4 has just invited the producer to re-send the same bytes. Without this, that invited retry would come back as an absorbed duplicate carrying the same failure forever.override -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited