package stmtcache
import "github.com/jackc/pgx/v5/internal/stmtcache"
Package stmtcache is a cache that can be used to implement lazy prepared statements.
Index ¶
- Constants
- type Cache
- type LRU
- func NewLRU(conn *pgconn.PgConn, mode int, cap int) *LRU
- func (c *LRU) Cap() int
- func (c *LRU) Clear(ctx context.Context) error
- func (c *LRU) Get(ctx context.Context, sql string) (*pgconn.StatementDescription, error)
- func (c *LRU) Len() int
- func (c *LRU) Mode() int
- func (c *LRU) StatementErrored(sql string, err error)
Constants ¶
const ( ModePrepare = iota // Cache should prepare named statements. ModeDescribe // Cache should prepare the anonymous prepared statement to only fetch the description of the statement. )
Types ¶
type Cache ¶
type Cache interface { // Get returns the prepared statement description for sql preparing or describing the sql on the server as needed. Get(ctx context.Context, sql string) (*pgconn.StatementDescription, error) // Clear removes all entries in the cache. Any prepared statements will be deallocated from the PostgreSQL session. Clear(ctx context.Context) error // StatementErrored informs the cache that the given statement resulted in an error when it // was last used against the database. In some cases, this will cause the cache to maer that // statement as bad. The bad statement will instead be flushed during the next call to Get // that occurs outside of a failed transaction. StatementErrored(sql string, err error) // Len returns the number of cached prepared statement descriptions. Len() int // Cap returns the maximum number of cached prepared statement descriptions. Cap() int // Mode returns the mode of the cache (ModePrepare or ModeDescribe) Mode() int }
Cache prepares and caches prepared statement descriptions.
func New ¶
New returns the preferred cache implementation for mode and cap. mode is either ModePrepare or ModeDescribe. cap is the maximum size of the cache.
type LRU ¶
type LRU struct {
// contains filtered or unexported fields
}
LRU implements Cache with a Least Recently Used (LRU) cache.
func NewLRU ¶
NewLRU creates a new LRU. mode is either ModePrepare or ModeDescribe. cap is the maximum size of the cache.
func (*LRU) Cap ¶
Cap returns the maximum number of cached prepared statement descriptions.
func (*LRU) Clear ¶
Clear removes all entries in the cache. Any prepared statements will be deallocated from the PostgreSQL session.
func (*LRU) Get ¶
Get returns the prepared statement description for sql preparing or describing the sql on the server as needed.
func (*LRU) Len ¶
Len returns the number of cached prepared statement descriptions.
func (*LRU) Mode ¶
Mode returns the mode of the cache (ModePrepare or ModeDescribe)
func (*LRU) StatementErrored ¶
Source Files ¶
- Version
- v5.0.0-alpha.3
- Published
- Apr 23, 2022
- Platform
- js/wasm
- Imports
- 5 packages
- Last checked
- 12 hours ago –
Tools for package owners.