querycacher

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type QueryCacher

type QueryCacher[TRes any] struct {
	baseservice.BaseService
	startstop.BaseStartStop
	// contains filtered or unexported fields
}

QueryCacher executes a database query periodically and caches the result. The basic premise is that given large River databases even simple queries like counting job rows can get quite slow. This construct operates as a background service that runs a query, stores the result, making it available to API endpoints so that they don't need to execute the query in band.

func NewQueryCacher

func NewQueryCacher[TRes any](archetype *baseservice.Archetype, db dbsqlc.DBTX, runQuery func(ctx context.Context, db dbsqlc.DBTX) (TRes, error)) *QueryCacher[TRes]

func (*QueryCacher[TRes]) CachedRes

func (s *QueryCacher[TRes]) CachedRes() (TRes, bool)

CachedRes returns cached results, if there are any, and an "ok" boolean indicating whether cached results were available (true if so, and false otherwise).

func (*QueryCacher[TRes]) RunQuery

func (s *QueryCacher[TRes]) RunQuery(ctx context.Context) (TRes, error)

RunQuery runs the internal query function and caches the result. It's not usually necessary to call this function explicitly since Start will do it periodically, but is made available for use in places like helping with testing.

func (*QueryCacher[TRes]) Start

func (s *QueryCacher[TRes]) Start(ctx context.Context) error

Start starts the service, causing it to periodically run its query and cache the result. It stops when Stop is called or if its context is cancelled.

Jump to

Keyboard shortcuts

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