# `Nous.Workflow.Scratch`
[🔗](https://github.com/nyo16/nous/blob/v0.17.1/lib/nous/workflow/scratch.ex#L1)

Optional per-workflow ETS table for large/binary data exchange between steps.

Use when workflow steps produce large data (fetched HTML, images, CSVs)
that shouldn't be copied through the immutable state pipeline. The scratch
table is created lazily and auto-cleaned on workflow completion.

## Usage

Enable via `scratch: true` option when running a workflow:

    {:ok, state} = Nous.Workflow.run(graph, %{}, scratch: true)

Inside a transform or handler:

    # Write large data
    Nous.Workflow.Scratch.put(scratch, :raw_html, large_binary)

    # Read it later
    html = Nous.Workflow.Scratch.get(scratch, :raw_html)

> #### The engine does not hand you the scratch {: .warning}
>
> `scratch: true` makes `Nous.Workflow.Engine` allocate a scratch for the run
> and clean it up on completion, but it is NOT attached to the workflow state —
> there is no `state.metadata.scratch`. Node functions reach a scratch only if
> you create one yourself with `new/0` and close over it (or thread it through
> `state.data` yourself), in which case you also own `cleanup/1`.
>
> Note `new/0` does not create the ETS table; the first `put/3` does, and only
> the struct it RETURNS carries the table id. Seed the closure with that
> returned struct, not with the result of `new/0`.

# `t`

```elixir
@type t() :: %Nous.Workflow.Scratch{id: String.t(), table: :ets.tid() | nil}
```

# `cleanup`

```elixir
@spec cleanup(t()) :: :ok
```

Clean up the scratch ETS table. Called automatically on workflow completion.

# `delete`

```elixir
@spec delete(t(), term()) :: :ok
```

Delete a key from the scratch space.

# `get`

```elixir
@spec get(t(), term(), term()) :: term()
```

Retrieve a value from the scratch space.

# `new`

```elixir
@spec new() :: t()
```

Create a new scratch space (lazily — ETS table created on first write).

# `put`

```elixir
@spec put(t(), term(), term()) :: t()
```

Store a value in the scratch space.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
