ETS-based prepared statement cache for ScyllaDB/Cassandra queries.
Caches prepared statements keyed by query hash to eliminate repeated query parsing overhead on ScyllaDB. This is especially impactful for high-throughput workloads where the same queries are executed repeatedly.
All ETS operations are routed through the GenServer to avoid race conditions when multiple processes access the cache concurrently.
Usage
AshScylla.PreparedStatementCache.prepare(repo, "SELECT * FROM users WHERE id = ?")Starting the Cache
Add to your supervision tree:
children = [
AshScylla.PreparedStatementCache,
# ... other children
]Or start manually:
AshScylla.PreparedStatementCache.start_link([])
Summary
Functions
Returns a specification to start this module under a supervisor.
Clears all cached prepared statements.
Invalidates a specific cached statement by CQL string.
Prepares a CQL statement, using the cache if available.
Returns the number of cached statements.
Starts the prepared statement cache.
Returns the ETS table tid for inspection/testing.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec clear() :: :ok
Clears all cached prepared statements.
@spec invalidate(String.t()) :: :ok
Invalidates a specific cached statement by CQL string.
Prepares a CQL statement, using the cache if available.
Returns {:ok, stmt} on success or {:error, reason} on failure.
@spec size() :: non_neg_integer()
Returns the number of cached statements.
@spec start_link(keyword()) :: GenServer.on_start()
Starts the prepared statement cache.
When no :name option is given, the GenServer is registered globally
as {:global, __MODULE__} so that all processes share a single cache.
Pass name: :undefined or a custom name to register locally instead.
@spec table() :: :ets.tid() | nil
Returns the ETS table tid for inspection/testing.