Sqlcx.Server.StatementCache (sqlcx v2.0.0-rc.1) View Source
Implements a least-recently used (LRU) cache for prepared SQLite statements.
Caches a fixed number of prepared statements and purges the statements which were least-recently used when that limit is exceeded.
Link to this section Summary
Functions
Creates a new prepared statement cache.
Given a statement cache and an SQL statement (string), returns a tuple containing the updated statement cache and a prepared SQL statement.
Link to this section Types
Specs
t() :: %Sqlcx.Server.StatementCache{ cached_stmts: %{required(String.t()) => Sqlcx.Statement.t()}, db: Sqlcx.connection(), limit: pos_integer(), lru: [String.t()], size: non_neg_integer() }
Link to this section Functions
Specs
new(Sqlcx.connection(), pos_integer()) :: t()
Creates a new prepared statement cache.
Specs
prepare(t(), String.t(), Sqlcx.Statement.prepare_options()) :: {t(), Sqlcx.Statement.t()}
Given a statement cache and an SQL statement (string), returns a tuple containing the updated statement cache and a prepared SQL statement.
If possible, reuses an existing prepared statement. If not, prepares the statement and adds it to the cache, possibly removing the least-recently used prepared statement if the designated cache size limit would be exceeded.
Will return {:error, reason}
if SQLite is unable to prepare the statement.