setStmtCacheSize method
Set the statement cache size.
Changes the maximum number of statements that can be cached. Larger cache sizes improve performance for applications that repeatedly execute the same SQL statements.
Parameters:
size: Cache size (number of statements, typically 20-100)
Example - Increase Cache for Better Performance:
// Default is usually 20, increase for apps with many unique queries
await connection.setStmtCacheSize(50);
// Now repeatedly executed statements will be cached
for (var i = 0; i < 1000; i++) {
await connection.query('SELECT * FROM users WHERE id = :1', params: [i]);
// Statement is prepared once and reused
}
Tip: Set this early in the connection lifecycle, before executing statements. A good value depends on how many unique SQL statements your application uses.
See also:
- getStmtCacheSize to get the current cache size
Implementation
Future<void> setStmtCacheSize(int size) async {
_ensureConnected();
final result = _dpiOracle.dpiConn_setStmtCacheSize(
_connectionPtr.value,
size,
);
if (result == DPI_FAILURE) {
throw OracleConnectionException('Failed to set statement cache size');
}
}