local

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package local is a local repo's query cache, as anfra's own process holds it: the repo's store, opened at first use, its canal-lake, started at first use, and the cache's state as anfra status reports it (a querycache.Summarizer). A platform serving managed repos supplies its own store and canal-lake instead. The cache's algorithm and contract are internal/querycache; anfra's store is store/sqlite.

Import it as localquerycache, so a call site says what is local:

import localquerycache "github.com/holistics/anfra/internal/querycache/local"

cache := localquerycache.New(dir, localquerycache.Options{Lake: lake})

See docs/designs/query-cache.md.

Index

Constants

View Source
const NamespaceEnv = "ANFRA_CACHE_QUERY_NAMESPACE"

NamespaceEnv sets Options.Namespace.

View Source
const NoticeOrphanedFiles = "query_cache_orphaned_files"

NoticeOrphanedFiles is a new store's lake folder already holding files, which no entry names.

Variables

View Source
var ErrDisabled = errors.New("the query cache is disabled")

ErrDisabled is Open's refusal when the cache is off.

Functions

func LakeDir

func LakeDir(dir string) string

LakeDir is canal-lake's storage for the query cache in dir, for starting the canal-lake the cache is then made with (New).

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache is a repo's query cache in this process: its folder, whether it is on, its store once opened, and its canal-lake. A process makes one, and closes it as it ends.

func New

func New(dir string, o Options) *Cache

New is the query cache in dir, the repo's folder for it. A namespace canal-lake can't take leaves the cache unusable, which Open and Summarize report, rather than failing here: a cache problem never fails a command.

func (*Cache) Close

func (c *Cache) Close(ctx context.Context) error

Close stops canal-lake and closes the store, those that were started.

ctx carries the trace its log records join; it is not for cancellation.

func (*Cache) Contents

func (c *Cache) Contents(ctx context.Context) (command.QueryCacheContents, error)

Contents are what the store holds now, read without creating, changing or migrating it, and the cache's folder.

func (*Cache) Disabled

func (c *Cache) Disabled() (string, bool)

Disabled says why the cache is off, and whether it is.

func (*Cache) Explain

func (c *Cache) Explain(err error) (problem, hint string)

Explain is what a failure to open the store means to the person running anfra: a problem, and what to do about it.

func (*Cache) LakeDir

func (c *Cache) LakeDir() string

LakeDir is canal-lake's storage: its files, and DuckDB's temporary ones.

func (*Cache) Manager

func (c *Cache) Manager(ctx context.Context) (*querycache.Manager, error)

Manager is the cache's manager: the store open, created and its notices told the first time. An error is why it can't be used now; the next query tries again.

func (*Cache) Namespace

func (c *Cache) Namespace() string

Namespace prefixes the names of the cache's files in canal-lake: empty, or segments each ending in "/" (querycache.Config.Namespace).

func (*Cache) Open

func (c *Cache) Open(ctx context.Context) (*sqlitestore.Store, []Notice, error)

Open is the store, opened (and created or brought up to date) the first time, and the same store after. A failure leaves it unopened, so the next Open tries again. Creating a store reports the files its lake folder already holds, which no entry names: anfra never deletes them itself (docs/designs/query-cache.md#file-names).

func (*Cache) Report

func (c *Cache) Report(ctx context.Context, err error)

Report tells whoever runs anfra why a query ran without the cache.

func (*Cache) Settings

func (c *Cache) Settings() command.QueryCacheSettings

Settings are the repo's cache settings, as a query uses them.

func (*Cache) StartLake

func (c *Cache) StartLake(ctx context.Context) error

StartLake starts canal-lake unless it runs already, for canal-query to write results to and read them from.

func (*Cache) StorePath

func (c *Cache) StorePath() string

StorePath is the store's file.

func (*Cache) Summarize

func (c *Cache) Summarize(ctx context.Context) querycache.Summary

Summarize reads the cache's state: only the store's header, so it never creates, changes or migrates the store.

type Lake

type Lake interface {
	Start(ctx context.Context) error
	Close(ctx context.Context)
}

Lake is canal-lake as the cache runs it: started when first needed, and again if it exited (canallake.Sidecar).

type Notice

type Notice struct {
	Code    string
	Message string
}

Notice is something to tell the person running anfra that doesn't stop the cache, with its code.

type Options

type Options struct {
	// Disabled says why the cache is off, as anfra status reports it; empty,
	// it is on.
	Disabled string
	// MaxDuration is the repo's cap on a query's cache duration: zero,
	// querycache.MaxDuration (command.QueryCacheSettings.MaxDuration).
	MaxDuration time.Duration
	// Lake is its canal-lake; nil when the cache is off.
	Lake Lake
	// Namespace is the subfolder of canal-lake's storage its files go in, as
	// the person running anfra gives it: word segments joined by "/", such as
	// prod or prod/eu; empty for the storage's top level
	// (docs/designs/query-cache.md#file-names).
	Namespace string
	// Report and Notice are how whoever runs anfra is told why a query ran
	// without the cache, and of what doesn't stop it (Open's notices). Nil
	// tells no one.
	Report func(ctx context.Context, err error)
	Notice func(ctx context.Context, n Notice)
}

Options are how a process runs the repo's query cache.

Jump to

Keyboard shortcuts

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