mycocepurus-smithii - v2.0.1
    Preparing search index...

    Class MemoryStore<T>

    In-process store. Evicts the least recently used entry once maxEntries is exceeded, and treats entries past their lease or retention as absent.

    claim is atomic here because JavaScript is single-threaded and there is no await between the check and the write. That is a fact about one process. Two replicas with two of these will both run the same key, which is why the interface exists and this class is only one of its stores.

    Type Parameters

    • T = unknown

    Implements

    Index
    • get size(): number

      How many entries are held right now. Useful in tests, not a policy input.

      Returns number

    • Write entry only if nothing live is held under key. Returns "claimed", or what is held.

      Parameters

      • key: string
      • entry: {
            claimedAt: number;
            fingerprint: string;
            leaseFor: number;
            owner: string;
            state: "in-flight";
        }
        • claimedAt: number

          When the claim was taken.

        • fingerprint: string
        • leaseFor: number

          How long past claimedAt the claim is honoured before the attempt is presumed dead.

        • owner: string

          Random per attempt. complete and release act only while the claim under the key still carries it, so an attempt that outlived its lease cannot touch the claim of the attempt that replaced it.

        • state: "in-flight"

      Returns Promise<"claimed" | Entry<T>>

    • Expiry is measured against this store's own clock, not the writer's.

      Parameters

      Returns Promise<boolean>

    • Drop whatever is held, whoever holds it. Called by Ledger.forget.

      Parameters

      • key: string

      Returns Promise<void>

    • Drop the claim, only if key holds a claim whose owner is owner. Returns whether it did. Called when an action threw or shouldStore declined.

      Parameters

      • key: string
      • owner: string

      Returns Promise<boolean>