PreparedStatementsCache<S extends Object> class

A cache of prepared statements S by SQL text, of one connection (or one database handle): the least recently used one is evicted (and released by onEvict) when it's over maxSize.

A SQL text is prepared at its prepareOnSightingth use (shouldPrepare): 1 prepares it the first time, 2 only when it repeats (when preparing costs a round trip, a statement run once doesn't pay it).

Constructors

PreparedStatementsCache({required int maxSize, required void onEvict(S statement), int prepareOnSighting = 1, PreparedStatementsInfo? info})

Properties

hashCode → int
The hash code for this object.
no setterinherited
info → PreparedStatementsInfo
The counters (shared by the caches of an adapter).
final
length → int
The number of cached statements.
no setter
maxSize → int
The maximum number of cached statements.
final
onEvict → void Function(S statement)
Releases an evicted (or cleared) statement.
final
prepareOnSighting → int
The use of a SQL text at which it's prepared (>= 1).
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

clear() → void
Removes (and releases) all the statements.
contains(String sql) → bool
Whether sql has a cached statement.
get(String sql) → S?
The cached statement of sql (marked as the most recently used), or null.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
put(String sql, S statement) → void
Caches statement of sql, evicting the least recently used ones over maxSize.
removeStale(String sql) → void
Removes (and releases) the statement of sql, when it's stale.
shouldPrepare(String sql) → bool
Whether sql (not cached) should be prepared now: counts its use, and returns true at its prepareOnSightingth one.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

checkMaxSize(int maxSize, [String name = 'maxSize']) → void
Throws an ArgumentError if maxSize is not a valid maxSize (>= 1): for an adapter to reject it when constructed, before opening a connection for its cache.