func StatementName(sql string) string
StatementName returns a statement name that will be stable for sql across multiple connections and program executions.
Cache caches statement descriptions.
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() // GetInvalidated returns a slice of all statement descriptions invalidated since the last call to RemoveInvalidated. GetInvalidated() []*pgconn.StatementDescription // RemoveInvalidated removes all invalidated statement descriptions. No other calls to Cache must be made between a // call to GetInvalidated and RemoveInvalidated or RemoveInvalidated may remove statement descriptions that were // never seen by the call to GetInvalidated. RemoveInvalidated() // Len returns the number of cached prepared statement descriptions. Len() int // Cap returns the maximum number of cached prepared statement descriptions. Cap() int }
LRUCache implements Cache with a Least Recently Used (LRU) cache.
type LRUCache struct {
// contains filtered or unexported fields
}
func NewLRUCache(cap int) *LRUCache
NewLRUCache creates a new LRUCache. cap is the maximum size of the cache.
func (c *LRUCache) Cap() int
Cap returns the maximum number of cached prepared statement descriptions.
func (c *LRUCache) Get(key string) *pgconn.StatementDescription
Get returns the statement description for sql. Returns nil if not found.
func (c *LRUCache) GetInvalidated() []*pgconn.StatementDescription
GetInvalidated returns a slice of all statement descriptions invalidated since the last call to RemoveInvalidated.
func (c *LRUCache) Invalidate(sql string)
Invalidate invalidates statement description identified by sql. Does nothing if not found.
func (c *LRUCache) InvalidateAll()
InvalidateAll invalidates all statement descriptions.
func (c *LRUCache) Len() int
Len returns the number of cached prepared statement descriptions.
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 or sd.SQL has been invalidated and HandleInvalidated has not been called yet.
func (c *LRUCache) RemoveInvalidated()
RemoveInvalidated removes all invalidated statement descriptions. No other calls to Cache must be made between a call to GetInvalidated and RemoveInvalidated or RemoveInvalidated may remove statement descriptions that were never seen by the call to GetInvalidated.
UnlimitedCache implements Cache with no capacity limit.
type UnlimitedCache struct {
// contains filtered or unexported fields
}
func NewUnlimitedCache() *UnlimitedCache
NewUnlimitedCache creates a new UnlimitedCache.
func (c *UnlimitedCache) Cap() int
Cap returns the maximum number of cached prepared statement descriptions.
func (c *UnlimitedCache) Get(sql string) *pgconn.StatementDescription
Get returns the statement description for sql. Returns nil if not found.
func (c *UnlimitedCache) GetInvalidated() []*pgconn.StatementDescription
GetInvalidated returns a slice of all statement descriptions invalidated since the last call to RemoveInvalidated.
func (c *UnlimitedCache) Invalidate(sql string)
Invalidate invalidates statement description identified by sql. Does nothing if not found.
func (c *UnlimitedCache) InvalidateAll()
InvalidateAll invalidates all statement descriptions.
func (c *UnlimitedCache) Len() int
Len returns the number of cached prepared statement descriptions.
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.
func (c *UnlimitedCache) RemoveInvalidated()
RemoveInvalidated removes all invalidated statement descriptions. No other calls to Cache must be made between a call to GetInvalidated and RemoveInvalidated or RemoveInvalidated may remove statement descriptions that were never seen by the call to GetInvalidated.