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

In-memory struct store backed by SuperCache ETS partitions.

Works transparently in both **local** and **distributed** modes — the
mode is determined by the `:cluster` option passed to `SuperCache.start!/1`.

Call `init/2` once per struct type before using `add/1`, `get/1`, etc.

## Read modes (distributed)

Pass `read_mode: :primary` or `read_mode: :quorum` for stronger consistency.

## Example

    alias SuperCache.Struct, as: S

    defmodule Order do
      defstruct [:id, :customer, :status]
    end

    S.init(%Order{}, :id)
    S.add(%Order{id: "o-1", customer: "Alice", status: :pending})
    S.get(%Order{id: "o-1"})
    # => {:ok, %Order{id: "o-1", customer: "Alice", status: :pending}}

# `add`

```elixir
@spec add(map()) :: {:ok, map()} | {:error, any()}
```

# `get`

```elixir
@spec get(
  map(),
  keyword()
) :: {:ok, map()} | {:error, :not_found | any()}
```

# `get_all`

```elixir
@spec get_all(
  map(),
  keyword()
) :: {:ok, list()} | {:error, any()}
```

# `init`

```elixir
@spec init(map(), atom()) :: true | {:error, any()}
```

# `remove`

```elixir
@spec remove(map()) :: {:ok, map()} | {:error, any()}
```

# `remove_all`

```elixir
@spec remove_all(map()) :: {:ok, :removed} | {:error, any()}
```

---

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