Class IdempotencyKey

java.lang.Object
com.tnsai.idempotency.IdempotencyKey

public final class IdempotencyKey extends Object
Derives stable idempotency keys from tool / action input maps per KeyStrategy (issue #91).

The KeyStrategy.HASH_INPUT path computes SHA-256 over a canonical JSON-like rendering of the input map: keys are sorted alphabetically at every level of nesting, lists keep their insertion order, scalars are stringified with locale-independent rules. Two inputs that differ only in map iteration order produce the same key — which is the property the dedup cache needs for the JVM's non-deterministic HashMap.entrySet() ordering not to accidentally split cache slots.

The KeyStrategy.UUID path returns a fresh random key every call. The KeyStrategy.NONE path returns null — the caller MUST short-circuit before invoking and must not pass null onward to the store.

Since:
0.5.0 (issue #91)
  • Method Details

    • derive

      public static String derive(KeyStrategy strategy, Map<String,Object> input, String toolName)
      Compute the idempotency key for the given input under strategy.
      Parameters:
      strategy - how to derive
      input - the call's argument map; treated as empty when null
      toolName - identifies the tool — incorporated into the key so different tools with identical-shaped inputs don't collide on the same hash
      Returns:
      the key, or null when strategy == NONE