# `PhoenixMicro.Middleware.CircuitBreaker.Store`
[🔗](https://github.com/iamkanishka/phoenix_micro/blob/v1.0.0/lib/phoenix_micro/middleware/circuit_breaker.ex#L207)

ETS-backed store for circuit breaker state.

One entry per fuse name:

    {fuse_name, state, failure_window, opened_at}

Where:
- `state` is `:closed | {:open, monotonic_ms} | :half_open`
- `failure_window` is a list of `{monotonic_ms, :failure}` tuples
  used to count failures within the sliding time window.

The process owns the table so it survives crashes of consumers.

# `all_states`

```elixir
@spec all_states() :: [{term(), :closed | {:open, integer()} | :half_open}]
```

Returns a snapshot of all fuse states (useful for health checks).

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `record_failure`

```elixir
@spec record_failure(term(), pos_integer()) :: non_neg_integer()
```

Records a failure within the sliding window. Returns the current
failure count within the window.

# `record_success`

```elixir
@spec record_success(term()) :: :ok
```

Records a success — clears the failure window.

# `reset_all`

```elixir
@spec reset_all() :: :ok
```

Resets all fuses to CLOSED. Useful in tests.

# `set_closed`

```elixir
@spec set_closed(term()) :: :ok
```

Resets the breaker to CLOSED.

# `set_half_open`

```elixir
@spec set_half_open(term()) :: :ok
```

Transitions to HALF_OPEN for probe.

# `set_open`

```elixir
@spec set_open(term()) :: :ok
```

Trips the breaker to OPEN.

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

# `state`

```elixir
@spec state(term()) :: :closed | {:open, integer()} | :half_open
```

Returns the current state for the given fuse: :closed | {:open, ms} | :half_open

---

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