pgconn: github.com/jackc/pgconn/stmtcache Index | Files

package stmtcache

import "github.com/jackc/pgconn/stmtcache"

Package stmtcache is a cache that can be used to implement lazy prepared statements.

Index

Package Files

lru.go stmtcache.go

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.
)

type Cache Uses

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

    // 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 Uses

func New(conn *pgconn.PgConn, mode int, cap int) Cache

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 Uses

type LRU struct {
    // contains filtered or unexported fields
}

LRU implements Cache with a Least Recently Used (LRU) cache.

func NewLRU Uses

func NewLRU(conn *pgconn.PgConn, mode int, cap int) *LRU

NewLRU creates a new LRU. mode is either ModePrepare or ModeDescribe. cap is the maximum size of the cache.

func (*LRU) Cap Uses

func (c *LRU) Cap() int

Cap returns the maximum number of cached prepared statement descriptions.

func (*LRU) Clear Uses

func (c *LRU) Clear(ctx context.Context) error

Clear removes all entries in the cache. Any prepared statements will be deallocated from the PostgreSQL session.

func (*LRU) Get Uses

func (c *LRU) Get(ctx context.Context, sql string) (*pgconn.StatementDescription, error)

Get returns the prepared statement description for sql preparing or describing the sql on the server as needed.

func (*LRU) Len Uses

func (c *LRU) Len() int

Len returns the number of cached prepared statement descriptions.

func (*LRU) Mode Uses

func (c *LRU) Mode() int

Mode returns the mode of the cache (ModePrepare or ModeDescribe)

Package stmtcache imports 5 packages (graph) and is imported by 3 packages. Updated 2019-09-23. Refresh now. Tools for package owners.