class PG::StatementCache
The prepared statements of a connection, by their SQL: the least
recently used is closed when there are more than the capacity. Its
names are qz1, qz2, ... Used by PG::Connection#query.
cache = PG::StatementCache.new(2)
cache.add("SELECT 1") # => "qz1"
cache.add("SELECT 2") # => "qz2"
cache.lookup("SELECT 1") # => "qz1"
cache.add("SELECT 3") # => "qz3"
cache.take_closes # => ["qz2"]
Classes and modules
PG::StatementCache::SnapshotThe cache's state as an immutable value, to move it to another task with its connection (PG::Lease).
Class methods
def self.new(capacity: Int) -> PG::StatementCache
A cache of at most capacity statements (0: none, every query is
parsed afresh as the unnamed statement).
def self.new(snapshot: PG::StatementCache::Snapshot) -> PG::StatementCache
A cache in the state snapshot recorded.
Methods
def snapshot -> PG::StatementCache::Snapshot
The cache's state (the collections are immutable: nothing is copied).
def enabled? -> Bool
Whether the cache keeps statements at all.
def size -> Int
The number of statements kept.
def lookup(sql: String) -> String?
The name of the statement prepared for sql, if any, which becomes
the most recently used.
def next_name -> String
A name for a new statement, not used yet.
def add(sql: String, name: String? = …) -> String
Keeps sql prepared as name (a new name if none is given), and
returns the name; the least recently used statement beyond the
capacity is queued to be closed.
def make_room -> Void
Makes room for one more statement: the least recently used beyond the capacity is queued to be closed, so that the request preparing the new one closes it first.
def forget(sql: String) -> Void
Drops sql's statement, queuing it to be closed on the server.
def drop(sql: String) -> Void
Drops sql's statement without closing it (the server has none).
def clear -> Void
Drops every statement without closing them (DISCARD ALL,
DEALLOCATE ALL: the server closed them).
def take_closes -> Array[String]
The statements to close, which are then forgotten.