# `SuperCache.Bootstrap`
[🔗](https://github.com/ohhi-vn/super_cache/blob/main/lib/bootstrap.ex#L1)

Unified startup and shutdown for SuperCache.

Handles both `:local` (single-node) and `:distributed` (cluster) modes.
The mode is selected via the `:cluster` option:

- `:local` (default) — single-node ETS cache, no replication.
- `:distributed` — cluster-aware; delegates to `SuperCache.Cluster.Bootstrap`.

## Options

| Option              | Type    | Default         | Description                          |
|---------------------|---------|-----------------|--------------------------------------|
| `:key_pos`          | integer | `0`             | Tuple index used as the ETS key      |
| `:partition_pos`    | integer | `0`             | Tuple index used to select partition |
| `:cluster`          | atom    | `:local`        | `:local` or `:distributed`           |
| `:num_partition`    | integer | scheduler count | Number of ETS partitions             |
| `:table_type`       | atom    | `:set`          | ETS table type                       |
| `:table_prefix`     | string  | `"SuperCache…"` | Prefix for ETS table atom names      |

Additional options for `:distributed` mode (see `SuperCache.Cluster.Bootstrap`):

| Option               | Type    | Default  | Description                        |
|----------------------|---------|----------|------------------------------------|
| `:replication_factor`| integer | `2`      | Total copies (primary + replicas)  |
| `:replication_mode`  | atom    | `:async` | `:async`, `:sync`, or `:strong`    |

## Examples

Start with defaults (local mode):

    SuperCache.Bootstrap.start!()

Start with custom configuration:

    opts = [
      key_pos: 0,
      partition_pos: 1,
      num_partition: 8,
      table_type: :bag
    ]
    SuperCache.Bootstrap.start!(opts)

Stop the cache and release all resources:

    SuperCache.Bootstrap.stop()

# `start!`

```elixir
@spec start!() :: :ok
```

Start SuperCache with default options (local mode).

Uses `key_pos: 0`, `partition_pos: 0`, `cluster: :local`, and `table_type: :set`.
The number of partitions defaults to the number of online schedulers.

## Examples

    SuperCache.Bootstrap.start!()
    # => :ok

# `start!`

```elixir
@spec start!(keyword()) :: :ok
```

Start SuperCache with the given keyword options.

Validates all options before starting. Raises `ArgumentError` if any
option is invalid or missing.

## Options

See module documentation for the full list of supported options.

## Examples

    SuperCache.Bootstrap.start!(key_pos: 0, partition_pos: 1, num_partition: 4)
    # => :ok

    SuperCache.Bootstrap.start!(cluster: :invalid)
    # => ** (ArgumentError) unsupported cluster mode: :invalid

# `stop`

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

Stop SuperCache and release all ETS resources.

Gracefully shuts down buffers, storage partitions, and the partition
registry. Configuration is preserved so the cache can be restarted
with the same settings.

## Examples

    SuperCache.Bootstrap.stop()
    # => :ok

---

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