An Orchid.Runner.Hook that transparently intercepts step execution and
serves results from cache when possible.
How It Works
For every step in the workflow, the hook:
Checks cacheability — the step must have
cache: truein its options, and both:meta_storeand:blob_storemust be present in the workflow baggage. If either condition is false the step is executed normally.Derives a cache key — delegates to
OrchidStratum.HashKeyBuilder.step_key/4.Probes the Meta Store — if a
MetaItemexists for the key and every referenced blob is still reachable in the Blob Store, the cached outputs are returned immediately (cache hit).Executes the step on a miss — hydrates any
{:ref, ...}inputs back to their raw payloads, calls the underlying step, then dehydrates the outputs (storing payloads in the Blob Store and replacing them with{:ref, blob_store, hash}tuples) and persists a newMetaItem.
Enabling the Hook
The hook is registered as a global hook in Orchid options:
opts = [
baggage: %{
meta_store: {MyMetaAdapter, meta_ref},
blob_store: {MyBlobAdapter, blob_ref}
},
global_hooks_stack: [OrchidStratum.BypassHook]
]Or use OrchidStratum.apply_cache/4 to have this wired automatically.
Per-Step Control
| Step option | Effect |
|---|---|
cache: true | Enables caching for this step. |
cache: false (default) | Step is always executed; hook is a no-op. |
cache_keys: [:opt_a] | Only :opt_a from the step's opts is included in the cache key. |
Dehydration Contract
Dehydrated outputs carry payloads of the form {:ref, blob_store, hash}.
The blob_store component is the exact store configuration tuple
{Module, store_ref} so that the hook can route blob lookups to the correct
adapter instance, even in multi-session or multi-tenant scenarios.
Blob integrity is verified with BlobStorage.exists?/2 before every cache
hit, ensuring the hook is safe against store eviction or external deletion.
Summary
Functions
Callback implementation for Orchid.Runner.Hook.call/2.
Functions
@spec call(Orchid.Runner.Context.t(), Orchid.Runner.Hook.next_fn()) :: Orchid.Runner.Hook.hook_result()
Callback implementation for Orchid.Runner.Hook.call/2.