AshScylla.PreparedStatementCache (AshScylla v0.3.0)

Copy Markdown View Source

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.

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 name for inspection/testing.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear()

@spec clear() :: :ok

Clears all cached prepared statements.

invalidate(cql)

@spec invalidate(String.t()) :: :ok

Invalidates a specific cached statement by CQL string.

prepare(repo, cql, opts \\ [])

@spec prepare(module(), String.t(), keyword()) :: {:ok, term()} | {:error, term()}

Prepares a CQL statement, using the cache if available.

Returns {:ok, stmt} on success or {:error, reason} on failure.

size()

@spec size() :: non_neg_integer()

Returns the number of cached statements.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts the prepared statement cache.

table()

@spec table() :: atom()

Returns the ETS table name for inspection/testing.