pgcache

package
v0.0.31 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BackoffInitialInterval = 100 * time.Millisecond
	BackoffMultiplier      = 1.5
	BackoffMaxRetriess     = 3
)

Variables

View Source
var (
	ErrNotLoaded        = errors.New("not loaded yet")
	ErrNotListening     = errors.New("not listening yet")
	ErrInvalidUpdate    = errors.New("invalid update")
	ErrAlreadyCommitted = errors.New("already committed")
)
View Source
var ErrUnexpectedEvenType = errors.New("unexpected event type")

Functions

This section is empty.

Types

type Delete

type Delete[K Key[K], T Object[K]] func(ctx context.Context, tx pgx.Tx, keys []K) error

Delete deletes the given objects from the database.

type EvenType

type EvenType uint8
const (
	EventTypeStore EvenType = iota
	EventTypeDelete
)

func (EvenType) String

func (et EvenType) String() string

type Event

type Event[K Key[K]] struct {
	Type EvenType
	Key  K
}

func (Event[K]) String

func (e Event[K]) String() string

type FromString

type FromString[K Key[K]] func(str string) (*K, error)

type Get

type Get[K Key[K], T Object[K]] func(ctx context.Context, conn *pgxpool.Pool, keys []K) ([]T, error)

Get returns all objects matching the given keys from the database.

type Key

type Key[T any] interface {
	Less[T]
	String() string
}

type Less

type Less[T any] interface {
	Less(other T) bool
}

type List

type List[K Key[K], T Object[K]] func(ctx context.Context, conn *pgxpool.Pool) ([]T, error)

List returns ALL objects of this type from the database.

type Object

type Object[K Key[K]] interface {
	Key() K
}

type SortedMap

type SortedMap[K Key[K], V any] struct {
	// contains filtered or unexported fields
}

func NewSortedMap

func NewSortedMap[K Key[K], V any]() *SortedMap[K, V]

func (*SortedMap[K, V]) All

func (m *SortedMap[K, V]) All() iter.Seq2[K, V]

func (*SortedMap[K, V]) Between

func (m *SortedMap[K, V]) Between(from, to K) iter.Seq2[K, V]

func (*SortedMap[K, V]) Delete

func (m *SortedMap[K, V]) Delete(k K)

func (*SortedMap[K, V]) From

func (m *SortedMap[K, V]) From(from K) iter.Seq2[K, V]

func (*SortedMap[K, V]) Load

func (m *SortedMap[K, V]) Load(k K) (V, bool)

func (*SortedMap[K, V]) Store

func (m *SortedMap[K, V]) Store(k K, v V)

type Store

type Store[K Key[K], T Object[K]] func(ctx context.Context, tx pgx.Tx, objects []T) error

Store stores the given objects in the database.

type StringKey

type StringKey string

func StringKeyFromString

func StringKeyFromString(str string) (*StringKey, error)

func (StringKey) Less

func (s StringKey) Less(other StringKey) bool

func (StringKey) String

func (s StringKey) String() string

type Table

type Table[K Key[K], T Object[K]] struct {
	// contains filtered or unexported fields
}

func NewTable

func NewTable[K Key[K], T Object[K]](pool *pgxpool.Pool,
	table string,
	fromString func(str string) (*K, error),
	list List[K, T],
	get Get[K, T],
	store Store[K, T],
	del Delete[K, T],
	logger *slog.Logger) (*Table[K, T], error)

func (*Table[K, T]) Begin

func (t *Table[K, T]) Begin(ctx context.Context) (*TableTx[K, T], error)

func (*Table[K, T]) Between

func (t *Table[K, T]) Between(from, to K) iter.Seq[T]

func (*Table[K, T]) From

func (t *Table[K, T]) From(key K) iter.Seq[T]

func (*Table[K, T]) Get

func (t *Table[K, T]) Get(key K) (T, bool)

func (*Table[K, T]) List

func (t *Table[K, T]) List() iter.Seq[T]

func (*Table[K, T]) Metrics

func (t *Table[K, T]) Metrics() []prometheus.Collector

Metrics implements observability.Metrics.

func (*Table[K, T]) ReadinessChecks

func (t *Table[K, T]) ReadinessChecks() map[string]observability.Check

ReadinessChecks implements observability.ReadinessChecks.

func (*Table[K, T]) Run

func (t *Table[K, T]) Run(ctx context.Context, notify run.Notify) error

Run implements run.Runnable.

type TableTx

type TableTx[K Key[K], T Object[K]] struct {
	// contains filtered or unexported fields
}

func (*TableTx[K, T]) Commit

func (ttx *TableTx[K, T]) Commit(ctx context.Context) error

func (*TableTx[K, T]) Delete

func (ttx *TableTx[K, T]) Delete(ctx context.Context, keys []K) error

func (*TableTx[K, T]) Store

func (ttx *TableTx[K, T]) Store(ctx context.Context, objects []T) error

Jump to

Keyboard shortcuts

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