package stmtcache
import "github.com/jackc/pgx/v5/internal/stmtcache"
Package stmtcache is a cache for statement descriptions.
Index ¶
- func IsStatementInvalid(err error) bool
- func NextStatementName() string
- type Cache
- type LRUCache
- func NewLRUCache(cap int) *LRUCache
- func (c *LRUCache) Cap() int
- func (c *LRUCache) Get(key string) *pgconn.StatementDescription
- func (c *LRUCache) HandleInvalidated() []*pgconn.StatementDescription
- func (c *LRUCache) Invalidate(sql string)
- func (c *LRUCache) InvalidateAll()
- func (c *LRUCache) Len() int
- func (c *LRUCache) Put(sd *pgconn.StatementDescription)
- type UnlimitedCache
- func NewUnlimitedCache() *UnlimitedCache
- func (c *UnlimitedCache) Cap() int
- func (c *UnlimitedCache) Get(sql string) *pgconn.StatementDescription
- func (c *UnlimitedCache) HandleInvalidated() []*pgconn.StatementDescription
- func (c *UnlimitedCache) Invalidate(sql string)
- func (c *UnlimitedCache) InvalidateAll()
- func (c *UnlimitedCache) Len() int
- func (c *UnlimitedCache) Put(sd *pgconn.StatementDescription)
Functions ¶
func IsStatementInvalid ¶
func NextStatementName ¶
func NextStatementName() string
NextStatementName returns a statement name that will be unique for the lifetime of the program.
Types ¶
type Cache ¶
type Cache interface { // Get returns the statement description for sql. Returns nil if not found. Get(sql string) *pgconn.StatementDescription // Put stores sd in the cache. Put panics if sd.SQL is "". Put does nothing if sd.SQL already exists in the cache. Put(sd *pgconn.StatementDescription) // Invalidate invalidates statement description identified by sql. Does nothing if not found. Invalidate(sql string) // InvalidateAll invalidates all statement descriptions. InvalidateAll() // HandleInvalidated returns a slice of all statement descriptions invalidated since the last call to HandleInvalidated. HandleInvalidated() []*pgconn.StatementDescription // Len returns the number of cached prepared statement descriptions. Len() int // Cap returns the maximum number of cached prepared statement descriptions. Cap() int }
Cache caches statement descriptions.
type LRUCache ¶
type LRUCache struct {
// contains filtered or unexported fields
}
LRUCache implements Cache with a Least Recently Used (LRU) cache.
func NewLRUCache ¶
NewLRUCache creates a new LRUCache. cap is the maximum size of the cache.
func (*LRUCache) Cap ¶
Cap returns the maximum number of cached prepared statement descriptions.
func (*LRUCache) Get ¶
func (c *LRUCache) Get(key string) *pgconn.StatementDescription
Get returns the statement description for sql. Returns nil if not found.
func (*LRUCache) HandleInvalidated ¶
func (c *LRUCache) HandleInvalidated() []*pgconn.StatementDescription
func (*LRUCache) Invalidate ¶
Invalidate invalidates statement description identified by sql. Does nothing if not found.
func (*LRUCache) InvalidateAll ¶
func (c *LRUCache) InvalidateAll()
InvalidateAll invalidates all statement descriptions.
func (*LRUCache) Len ¶
Len returns the number of cached prepared statement descriptions.
func (*LRUCache) Put ¶
func (c *LRUCache) Put(sd *pgconn.StatementDescription)
Put stores sd in the cache. Put panics if sd.SQL is "". Put does nothing if sd.SQL already exists in the cache.
type UnlimitedCache ¶
type UnlimitedCache struct {
// contains filtered or unexported fields
}
UnlimitedCache implements Cache with no capacity limit.
func NewUnlimitedCache ¶
func NewUnlimitedCache() *UnlimitedCache
NewUnlimitedCache creates a new UnlimitedCache.
func (*UnlimitedCache) Cap ¶
func (c *UnlimitedCache) Cap() int
Cap returns the maximum number of cached prepared statement descriptions.
func (*UnlimitedCache) Get ¶
func (c *UnlimitedCache) Get(sql string) *pgconn.StatementDescription
Get returns the statement description for sql. Returns nil if not found.
func (*UnlimitedCache) HandleInvalidated ¶
func (c *UnlimitedCache) HandleInvalidated() []*pgconn.StatementDescription
func (*UnlimitedCache) Invalidate ¶
func (c *UnlimitedCache) Invalidate(sql string)
Invalidate invalidates statement description identified by sql. Does nothing if not found.
func (*UnlimitedCache) InvalidateAll ¶
func (c *UnlimitedCache) InvalidateAll()
InvalidateAll invalidates all statement descriptions.
func (*UnlimitedCache) Len ¶
func (c *UnlimitedCache) Len() int
Len returns the number of cached prepared statement descriptions.
func (*UnlimitedCache) Put ¶
func (c *UnlimitedCache) Put(sd *pgconn.StatementDescription)
Put stores sd in the cache. Put panics if sd.SQL is "". Put does nothing if sd.SQL already exists in the cache.
Source Files ¶
lru_cache.go stmtcache.go unlimited_cache.go
- Version
- v5.4.2
- Published
- Jul 12, 2023
- Platform
- linux/amd64
- Imports
- 5 packages
- Last checked
- 11 hours ago –
Tools for package owners.