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
- Variables
- func LakeDir(dir string) string
- type Cache
- func (c *Cache) Close(ctx context.Context) error
- func (c *Cache) Contents(ctx context.Context) (command.QueryCacheContents, error)
- func (c *Cache) Disabled() (string, bool)
- func (c *Cache) Explain(err error) (problem, hint string)
- func (c *Cache) LakeDir() string
- func (c *Cache) Manager(ctx context.Context) (*querycache.Manager, error)
- func (c *Cache) Namespace() string
- func (c *Cache) Open(ctx context.Context) (*sqlitestore.Store, []Notice, error)
- func (c *Cache) Report(ctx context.Context, err error)
- func (c *Cache) Settings() command.QueryCacheSettings
- func (c *Cache) StartLake(ctx context.Context) error
- func (c *Cache) StorePath() string
- func (c *Cache) Summarize(ctx context.Context) querycache.Summary
- type Lake
- type Notice
- type Options
Constants ¶
const NamespaceEnv = "ANFRA_CACHE_QUERY_NAMESPACE"
NamespaceEnv sets Options.Namespace.
const NoticeOrphanedFiles = "query_cache_orphaned_files"
NoticeOrphanedFiles is a new store's lake folder already holding files, which no entry names.
Variables ¶
var ErrDisabled = errors.New("the query cache is disabled")
ErrDisabled is Open's refusal when the cache is off.
Functions ¶
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 ¶
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 ¶
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 ¶
Contents are what the store holds now, read without creating, changing or migrating it, and the cache's folder.
func (*Cache) Explain ¶
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) Manager ¶
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 ¶
Namespace prefixes the names of the cache's files in canal-lake: empty, or segments each ending in "/" (querycache.Config.Namespace).
func (*Cache) Open ¶
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) Settings ¶
func (c *Cache) Settings() command.QueryCacheSettings
Settings are the repo's cache settings, as a query uses them.
type Lake ¶
Lake is canal-lake as the cache runs it: started when first needed, and again if it exited (canallake.Sidecar).
type Notice ¶
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.