# `Octoroom.Store`
[🔗](https://github.com/samrat/octoroom/blob/v0.1.0/lib/octoroom/store.ex#L1)

Where Octoroom keeps what must outlive a room server or a node restart:
room records and what workers save. A small key-value behaviour, so it can
sit on ETS, Postgres or Redis.

Two tables:

  * `:rooms`: room id => `%{run: run_id, assigns: map, updated_at: unix_ms}`.
    Written when a room server starts and when its assigns change, deleted
    when the room stops because its last participant left. A record left
    behind means the room didn't stop cleanly, so the next room server with
    that id recovers it. `Octoroom.Janitor` deletes records whose room
    hasn't come back within a resume token's max age.
  * `:workers`: `{room id, worker id}` => whatever the worker last saved
    (the `save:` action of `Octoroom.Worker`), handed back as
    `ctx.saved` when it starts again. Deleted when the room stops the
    worker for good, when the room stops because its last participant
    left, when a fresh room with that id starts, and with the room's
    record by the janitor.

Workers' Cloudflare sessions need no records: each ends with its peer
connection.

The store holds no participant state: participants come back through
their resume tokens.

Configure with `config :octoroom, store: {module, opts}`. The default is
`{Octoroom.Store.ETS, []}`.

# `store`

```elixir
@type store() :: {module(), keyword()}
```

# `table`

```elixir
@type table() :: atom()
```

# `all`

```elixir
@callback all(keyword(), table()) :: [{term(), term()}]
```

# `child_spec`

```elixir
@callback child_spec(keyword()) :: Supervisor.child_spec() | nil
```

Child spec for the store's process, if it has one.

# `delete`

```elixir
@callback delete(keyword(), table(), key :: term()) :: :ok
```

# `get`

```elixir
@callback get(keyword(), table(), key :: term()) :: term() | nil
```

# `put`

```elixir
@callback put(keyword(), table(), key :: term(), value :: term()) :: :ok
```

# `all`

# `config`

```elixir
@spec config() :: store()
```

The configured store.

# `delete`

# `get`

# `put`

---

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