# `SuperCache.Partition.Holder`
[🔗](https://github.com/ohhi-vn/super_cache/blob/main/lib/partition/partition_holder.ex#L1)

Registry for partition ETS table names.

Maintains a mapping from partition index (integer) to the corresponding
ETS table atom.  The mapping is stored in a `:protected` ETS table owned
by this GenServer so that:

- Reads are lock-free (`:read_concurrency`).
- The table survives crashes as long as this GenServer is alive.
- Multiple processes can look up partitions concurrently without
  blocking each other.

## Lifecycle

1. On application start, `Partition.start/1` calls `set_num_partition/1`
   and `set/1` for each index to populate the registry.
2. During runtime, `get/1` and `get_all/1` are used by the routing layer
   to resolve partition tables.
3. On shutdown, `stop/0` clears the registry.

## Example

    SuperCache.Partition.Holder.set_num_partition(4)
    SuperCache.Partition.Holder.set(0)
    SuperCache.Partition.Holder.get(0)
    # => :"SuperCache.Storage.Ets_0"

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `clean`

```elixir
@spec clean() :: true
```

Clears all partition registrations from the ETS table.

Does NOT delete the ETS table itself — only removes its contents.

# `get`

```elixir
@spec get(non_neg_integer()) :: atom() | nil
```

Look up the ETS table atom for a given partition index.

Reads directly from the ETS table — no GenServer hop.
Raises if the index has not been registered.

## Examples

    SuperCache.Partition.Holder.get(0)
    # => :"SuperCache.Storage.Ets_0"

# `get_all`

```elixir
@spec get_all() :: [atom()]
```

Return all registered partition ETS table atoms.

Filters out non-partition entries (such as `:num_partition`).

# `set`

```elixir
@spec set(non_neg_integer()) :: :ok
```

Register a partition index with its corresponding ETS table name.

The table name is derived from the configured `:table_prefix` and the
given `order` (index).  For example, with prefix `"SuperCache.Storage.Ets"`
and order `2`, the table name will be `:"SuperCache.Storage.Ets_2"`.

# `set_num_partition`

```elixir
@spec set_num_partition(pos_integer()) :: :ok
```

Store the total number of partitions in the registry.

Used by `Partition.get_num_partition/0` to resolve the partition count
without a GenServer hop.

# `start_link`

```elixir
@spec start_link(keyword()) :: :ignore | {:error, any()} | {:ok, pid()}
```

Starts the Partition.Holder GenServer and its owned ETS table.

# `stop`

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

Stops the Partition.Holder GenServer.

The ETS table will be deleted when the GenServer terminates.

---

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