hyperlane-plugin-idempotency 23.3.0

A production HTTP Idempotency-Key middleware plugin for the Hyperlane framework featuring XxHash3_64 request fingerprinting (422 mismatch), 64-way sharded bounded InMemoryIdempotencyStore + async IdempotencyStore trait, InFlight concurrent duplicate guard (409 Conflict), and zero-copy cached response replay with Idempotent-Replayed headers.
Documentation
use super::*;

/// Pluggable asynchronous storage contract backing [`IdempotencyPlugin`].
pub trait IdempotencyStore: Send + Sync + 'static {
    /// Atomically checks an existing entry or acquires an exclusive `InFlight` lock for `key`.
    ///
    /// # Arguments
    ///
    /// - `&'a self` - Store reference.
    /// - `&'a str` - Scoped idempotency storage key.
    /// - `u64` - Request `(method, path, body)` `XxHash3_64` fingerprint.
    /// - `u64` - Maximum `InFlight` lock TTL in milliseconds.
    ///
    /// # Returns
    ///
    /// - `IdempotencyFuture<'a, IdempotencyLookup>` - Acquisition, conflict, mismatch, or cached replay result.
    fn acquire<'a>(
        &'a self,
        key: &'a str,
        fingerprint: u64,
        in_flight_ttl_ms: u64,
    ) -> IdempotencyFuture<'a, IdempotencyLookup>;

    /// Commits a completed response for `key` with the given `ttl_ms`.
    ///
    /// # Arguments
    ///
    /// - `&'a self` - Store reference.
    /// - `String` - Scoped idempotency storage key.
    /// - `u64` - Request `(method, path, body)` fingerprint.
    /// - `Arc<StoredIdempotentResponse>` - Cached response and prebuilt replay wire buffer.
    /// - `u64` - Replay cache TTL in milliseconds.
    ///
    /// # Returns
    ///
    /// - `IdempotencyFuture<'a, ()>` - Completion future.
    fn complete<'a>(
        &'a self,
        key: String,
        fingerprint: u64,
        response: Arc<StoredIdempotentResponse>,
        ttl_ms: u64,
    ) -> IdempotencyFuture<'a, ()>;

    /// Releases an `InFlight` entry without caching (for example on uncacheable `5xx` responses).
    ///
    /// # Arguments
    ///
    /// - `&'a self` - Store reference.
    /// - `&'a str` - Scoped idempotency storage key.
    ///
    /// # Returns
    ///
    /// - `IdempotencyFuture<'a, ()>` - Completion future.
    fn release<'a>(&'a self, key: &'a str) -> IdempotencyFuture<'a, ()>;

    /// Synchronous best-effort cleanup hook invoked when [`IdempotencyInFlightGuard`] drops early.
    ///
    /// # Arguments
    ///
    /// - `&str` - Scoped idempotency storage key.
    fn release_on_drop(&self, _key: &str) {}

    /// Evicts expired entries and returns the count removed.
    ///
    /// # Returns
    ///
    /// - `usize` - Number of expired entries evicted.
    fn purge_expired(&self) -> usize {
        0
    }
}