queryercache

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package queryercache provides cache for paginator Queryer interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheMetrics

type CacheMetrics interface {
	CountIncrement(cached bool)
	QueryIncrement(cached bool)
}

CacheMetrics specify interface for metrics methods.

type Option

type Option func(opt *options)

Option specify option for QueryerCache.

func WithCountTTL

func WithCountTTL(ttl time.Duration) Option

QueryerCache count cache ttl (default 30 seconds).

func WithMetrics

func WithMetrics(m CacheMetrics) Option

WithMetrics metrics provider for QueryerCache (default noop impl).

func WithQueryTTL

func WithQueryTTL(ttl time.Duration) Option

WithQueryTTL query cache ttl (default 30 seconds).

type QueryerCache

type QueryerCache[T any] struct {
	// contains filtered or unexported fields
}

QueryerCache implementing cache for paginator.Queryer interface.

func New

func New[T any](queryer paginator.Queryer[T], opts ...Option) *QueryerCache[T]

New conscturcts new QueryerCache.

func (*QueryerCache[T]) Count

func (q *QueryerCache[T]) Count(ctx context.Context) (int, error)

Count returns count value from cache if available and not expired. otherwise returns value from queryer.Count and update cache value.

func (*QueryerCache[T]) Query

func (q *QueryerCache[T]) Query(ctx context.Context, offset int, limit int) ([]T, error)

Query returns cached data value if available and not expired. otherwise returns value from queryer.Query and update cache value.

Directories

Path Synopsis
Package metrics provides metric support for QueryerCache.
Package metrics provides metric support for QueryerCache.

Jump to

Keyboard shortcuts

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