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 (*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.