Which caching strategy is faster and by how much?
1) PreparedStatement pooling (by the connection pool). No caching by the application.
for (int i=0; i<1000; i++) {
PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.setObject(1, someValue);
preparedStatement.executeQuery();
preparedStatement.close();
}
2) Application-level caching. No PreparedStatement pooling.
PreparedStatement preparedStatement = connection.prepareStatement(sql);
for (int i=0; i<1000; i++) {
preparedStatement.clearParameters();
preparedStatement.setObject(1, someValue);
preparedStatement.executeQuery();
}
preparedStatement.close();
This question is similar to Reusing a PreparedStatement multiple times except that I'm expecting concrete benchmark results as well as taking PreparedStatement pooling into consideration.
http://drupal.org/node/550124#comment-2224630 seems to indicate that application-level caching is more efficient than PreparedStatement pooling but the difference is negligible. I'd like to see more benchmarks before making up my mind.