pgx

package
v0.11.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package pgx provides a PostgreSQL implementation of cache.Cache.

Values are stored gob-encoded. When the cache is parameterised with V=any, decoding goes through *interface{} and gob requires the concrete value type to be pre-registered:

gob.Register(MyStruct{})

Without registration, Get returns "gob: type not registered for interface". Caches parameterised with a concrete V (e.g. Cache[string, MyStruct]) round-trip directly and need no registration.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound             = cache.ErrNotFound
	DefaultOperationTimeout = 10 * time.Second
	DefaultCleanupInterval  = 5 * time.Minute
	DefaultTableName        = "cache_entries"
)

Functions

This section is empty.

Types

type Cache

type Cache[K ~string, V any] struct {
	// contains filtered or unexported fields
}

func New

func New[K ~string, V any](ctx context.Context, pool *pgxpool.Pool, opts ...Option[K, V]) (*Cache[K, V], error)

func NewStdLib

func NewStdLib[K ~string, V any](ctx context.Context, db *sql.DB, opts ...Option[K, V]) (*Cache[K, V], error)

func (*Cache[K, V]) Add added in v0.11.0

func (c *Cache[K, V]) Add(key K, value V, ttl time.Duration) (bool, error)

func (*Cache[K, V]) Close

func (c *Cache[K, V]) Close() error

func (*Cache[K, V]) Get

func (c *Cache[K, V]) Get(key K) (V, error)

func (*Cache[K, V]) Keys

func (c *Cache[K, V]) Keys(prefix K) []K

func (*Cache[K, V]) Pop

func (c *Cache[K, V]) Pop(key K) (V, error)

func (*Cache[K, V]) Remove

func (c *Cache[K, V]) Remove(keys ...K) error

func (*Cache[K, V]) Set

func (c *Cache[K, V]) Set(key K, value V, ttl time.Duration) error

type Option

type Option[K ~string, V any] func(*Cache[K, V])

func WithTableName

func WithTableName[K ~string, V any](name string) Option[K, V]

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL