7#include "SqlOdbcPrelude.hpp"
15#include <unordered_map>
103 [[nodiscard]] std::
size_t Capacity() const noexcept
115 return m_capacity != 0;
119 [[nodiscard]] std::size_t
Size() const noexcept
121 return m_entries.size();
146 [[nodiscard]] LIGHTWEIGHT_API std::optional<PreparedHandle>
Acquire(std::string_view query)
noexcept;
159 LIGHTWEIGHT_API
void Clear() noexcept;
170 using EntryList = std::list<Entry>;
173 void EraseFromIndex(EntryList::const_iterator entry)
noexcept;
176 void EvictSurplus() noexcept;
178 std::
size_t m_capacity;
180 std::unordered_multimap<std::string_view, EntryList::iterator> m_index;
181 Statistics m_stats {};
A bounded LRU pool of already-prepared ODBC statement handles, owned by a SqlConnection.
LIGHTWEIGHT_API std::optional< PreparedHandle > Acquire(std::string_view query) noexcept
Takes an idle handle prepared for query out of the pool.
Statistics const & Stats() const noexcept
std::size_t Size() const noexcept
LIGHTWEIGHT_API void SetCapacity(std::size_t capacity) noexcept
Sets the capacity, evicting the least recently released handles when shrinking.
bool IsEnabled() const noexcept
LIGHTWEIGHT_API void ResetStatistics() noexcept
Resets the cumulative counters to zero, leaving the pooled handles untouched.
LIGHTWEIGHT_API SqlPreparedStatementCache(std::size_t capacity=0) noexcept
Constructs a cache with the given capacity.
std::size_t Capacity() const noexcept
void RecordDirectReuse() noexcept
LIGHTWEIGHT_API void Release(std::string_view query, PreparedHandle handle) noexcept
Hands a prepared handle back to the pool as the most recently used entry.
LIGHTWEIGHT_API void Clear() noexcept
Frees every pooled handle, e.g. after DDL invalidated the cached query plans.
SqlPreparedStatementCaching
Whether a single SqlStatement takes part in its connection's prepared-statement cache.
@ Enabled
Request an encrypted connection (SQL_EN_ON).
@ Disabled
Request an unencrypted connection (SQL_EN_OFF).
A pooled statement handle together with the parameter count the driver reported for it.
SQLHSTMT nativeHandle
The native ODBC statement handle, prepared for the associated query text.
SQLSMALLINT parameterCount
The number of input parameters SQLNumParams reported for that query.
Cumulative counters, primarily for tests and diagnostics.
uint64_t misses
Prepare requests that had to issue SQLPrepare.
uint64_t evictions
Pooled handles freed because the capacity bound was exceeded.
uint64_t hits
Prepare requests served from the pool, i.e. reusing a handle the server already prepared.