# `Spectre.State.Store`
[🔗](https://github.com/elchemista/spectre/blob/0.4.0/lib/spectre/state/store.ex#L1)

Durable state-adapter contract with optimistic concurrency.

New adapters should implement `compare_and_swap/5`. Spectre passes the state
containing `expected_revision + 1` together with the expected prior revision.
Return `{:error, :stale_state}` (or `{:error, {:stale_state, actual}}`) when
another turn committed first. If the store cannot determine whether a write
committed, return `{:error, {:ambiguous, reason}}`; Spectre will not retry it
blindly. Spectre also treats an invoked persistence callback that crashes,
exits, throws, times out, or returns a malformed success envelope as
ambiguous because the failure may have happened after the durable commit.

# `compare_and_swap`
*optional* 

```elixir
@callback compare_and_swap(
  Spectre.State.t(),
  non_neg_integer(),
  Spectre.Input.t(),
  module(),
  keyword()
) :: :ok | {:ok, Spectre.State.t() | map() | String.t()} | {:error, term()}
```

# `load`
*optional* 

```elixir
@callback load(Spectre.Input.t(), module(), keyword()) ::
  {:ok, Spectre.State.t() | map() | String.t()} | {:error, term()}
```

---

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