ETS-backed local cache of subscribed SpacetimeDB tables.
Maintains a mirror of server state by processing subscription and
transaction update events from a Spacetimedbex.Connection.
Usage
{:ok, cache} = Spacetimedbex.ClientCache.start_link(
host: "localhost:3000",
database: "testmodule"
)
# After connection subscribes and events flow in:
Spacetimedbex.ClientCache.get_all(cache, "person")
Spacetimedbex.ClientCache.find(cache, "person", 1)
Spacetimedbex.ClientCache.count(cache, "person")
Summary
Functions
Returns a specification to start this module under a supervisor.
Count rows in a cached table.
Find a row by primary key value.
Get all rows from a cached table as a list of maps.
Process a SpacetimeDB event. Called by the connection handler to feed events into the cache.
Get the parsed schema.
Start the client cache.
Types
@type t() :: %Spacetimedbex.ClientCache{ ets_tables: %{required(String.t()) => :ets.table()}, handler: pid() | nil, schema: Spacetimedbex.Schema.t() | nil }
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Count rows in a cached table.
Find a row by primary key value.
Get all rows from a cached table as a list of maps.
Process a SpacetimeDB event. Called by the connection handler to feed events into the cache.
Get the parsed schema.
Start the client cache.
Options
:host- SpacetimeDB host (for schema fetch). Required unless:schemagiven.:database- Database name. Required unless:schemagiven.:schema- Optional pre-parsed%Schema{}. Skips HTTP fetch when provided.:handler- Optional PID to forward{:cache_event, event}notifications.:name- Optional process name.