OrchidIntervention.KeyBuilder (orchid_intervention v0.1.3)

Copy Markdown View Source

Deterministic key derivation for intervention caching.

Two tiers of keys:

  1. Intervention Key — identifies a specific intervention datum (type + target IO key + data digest). Read-only during DAG execution.

  2. Merge Result Key — identifies the outcome of merging step output with intervention data. Derived from the intervention key and optionally the inner result key, controlled by data_enable/0. Read + write during DAG execution.

Key Formulas

InterventionKey = MD5(term_to_binary({type_string, io_key_string, digest_binary}))

MergeResultKey  = MD5(term_to_binary(
  [intervention_key | if use_inner? -> [inner_result_key]]
))

MD5 is chosen deliberately: these are cache-eviction keys, not security primitives. The 128-bit space is sufficient and faster than SHA-256.

Summary

Functions

Derives a cache key for the intervention data itself.

Types

key_type()

@type key_type() :: binary()

Functions

get_digest(param)

intervention_key(type, io_key_name, data_digest)

@spec intervention_key(
  OrchidIntervention.intervention_type(),
  Orchid.Step.io_key(),
  term()
) ::
  key_type()

Derives a cache key for the intervention data itself.

data_digest is domain-specific:

  • For files: file metadata (size + mtime)
  • For network resources: URI + last-modified / etag
  • For in-memory data: a content hash or user-supplied fingerprint

merge_result_key(operate_mod, io_key, intervention_key, inner_result_key)

@spec merge_result_key(module(), Orchid.Step.io_key(), key_type(), key_type() | nil) ::
  key_type()

Derives a cache key for the merge result.

Uses data_enable/0 from the Operate module to decide which components participate in the key:

  • {false, true} (:override): inner result changes don't invalidate
  • {true, true} (:offset etc.): both sources invalidate
  • {true, false}: intervention data changes don't invalidate (unusual)