Class StatementCache


  • public class StatementCache
    extends Object
    Caches PreparedStatements and CallableStatements per Connection, local to the Thread.

    If using a modern jdbc driver that caches Statements (PG, Oracle, or MySQL), consider disabling this via its Home object, drivers cache Statements better. Bottom-up, the containment hierarchy is as follows:

    • A StmtCache (StatementCache.PerConnectionCache) is an LRU cache storing PreparedStatement or CallableStatements by their sql.
    • A StmtCacheMap is created if not exists from calls to prepareStatement or prepareCall and holds StmtCaches by their Connection key.
    • StmtCacheMap is a type of the static ThreadLocal created at startup so each thread gets its own StmtCacheMap.
    StmtCache guards against ever-changing PreparedStatement sql (not using params) by evicting the LRU entry per call if StmtCache is full or entry has expired.
    See Also:
    Let drivers cache PreparedStatements, StatementCacheListener, getConnKey(Connection)