# `SuperPi.Gateway.Sessions`
[🔗](https://github.com/oleksandr/super-pi-beam/blob/v0.1.0/lib/super_pi/gateway/sessions.ex#L1)

Stored mapping from a client session id to a conversation, per principal.

The mapping is a table, so it survives a restart and is shared by every node. The unique index
on `(principal, session_id)` decides a race between two requests (on one node or several): one
creates the mapping, the other finds it and discards the conversation it had made.

Rows idle longer than `config :super_pi, gateway_session_ttl_days` (default 90) are deleted,
and the table keeps at most `gateway_session_limit` rows (default 100_000), oldest first. A
deleted session id starts a new conversation.

# `count`

Number of stored sessions.

# `fetch_or_create`

Returns `{conversation_id, new?}`. `create_fun` makes a conversation when the session is new.

# `lookup`

The conversation id for a session, or `nil`.

# `prune`

Deletes expired rows and rows beyond the limit. Returns the number deleted.

---

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