cache

package
v0.23.0 Latest Latest
Warning

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

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

Documentation

Overview

Package cache is the commands on the repo's caches: cache.status reports what they hold, and cache.clean removes their entries. The query cache is the only one yet. See docs/designs/query-cache.md#cleaning.

Index

Constants

This section is empty.

Variables

View Source
var Clean = command.Define(command.Def[CacheCleanRequestParams, CacheCleanResult]{
	Name:  "cache.clean",
	Short: "Remove results from the repo's query cache, so that queries run on the warehouse again",
	Long: `Remove results from the repo's query cache, so that queries run on the warehouse again.

Clean after fixing data in the warehouse: from then on, no query is answered from a result read before the clean, including one still being written when it ran. Select what to remove by what the queries read, such as --query.data-source or --query.dataset. Without any, every cache of the repo is cleaned: today, every result of its query cache.`,
	Idempotent: true,
	Timeout:    time.Minute,

	Needs:  func(CacheCleanRequestParams) command.Sidecars { return command.Sidecars{CanalQuery: true} },
	Errors: []apperr.AnyCode{errcode.CacheDisabled, errcode.CacheUnavailable},
	Run:    clean,
})

Clean removes entries from the repo's query cache.

View Source
var Status = command.Define(command.Def[CacheStatusRequestParams, CacheStatusResult]{
	Name:  "cache.status",
	Short: "Show what the repo's caches hold, and where",
	Long: `Show what the repo's caches hold, and where: for the query cache, its state, its folder, its settings, and how many results it holds and their size.

It reads the caches without changing them. anfra status shows the same state, without the counts.`,
	ReadOnly:   true,
	Idempotent: true,
	Timeout:    time.Minute,
	Run:        status,
})

Status reports what the repo's caches hold, without changing them.

Functions

func LakeOf

LakeOf is the canal-lake qc's files are in, reached through canal: started before it drops anything, so a sweep with nothing to remove starts none.

func Sweep

Sweep removes every entry expired for longer than the read grace, a batch at a time, until none is left or ctx is done: what anfra serve runs, and a clean after it. What it removed before a failure is in its answer.

Types

type CacheCleanRequestParams

type CacheCleanRequestParams struct {
	Query *QueryCacheSelector `` /* 270-byte string literal not displayed */
}

CacheCleanRequestParams is what cache.clean takes: which of each cache's entries to remove.

func (CacheCleanRequestParams) TransformSchema

func (CacheCleanRequestParams) TransformSchema(_ huma.Registry, s *huma.Schema) *huma.Schema

type CacheCleanResult

type CacheCleanResult struct {
	Query *QueryCacheCleaned `json:"query,omitempty" doc:"what was removed from the query cache"`
}

CacheCleanResult is what cache.clean removed, from each cache it cleaned.

type CacheStatusRequestParams

type CacheStatusRequestParams struct{}

CacheStatusRequestParams is what cache.status takes: nothing yet. Every cache is reported, which today is the query cache alone.

func (CacheStatusRequestParams) TransformSchema

func (CacheStatusRequestParams) TransformSchema(_ huma.Registry, s *huma.Schema) *huma.Schema

type CacheStatusResult

type CacheStatusResult struct {
	Query *QueryCacheStatus `json:"query,omitempty" doc:"the query cache. Absent when the server keeps none."`
	Hints []string          `json:"hints,omitempty" doc:"what to do about a problem the caches have, if any"`
}

CacheStatusResult is what each of the repo's caches holds.

type Expired

type Expired struct {
	Entries int   `json:"entries" doc:"how many"`
	Bytes   int64 `json:"bytes" doc:"their size"`
}

Expired are results no query uses any more.

type QueryCacheCleaned

type QueryCacheCleaned struct {
	Entries int         `` /* 176-byte string literal not displayed */
	Bytes   int64       `` /* 238-byte string literal not displayed */
	Freed   *QueryFreed `` /* 220-byte string literal not displayed */
}

QueryCacheCleaned is what a clean removed from the query cache.

type QueryCacheContents

type QueryCacheContents struct {
	Entries        int        `json:"entries" doc:"how many cached results queries can be answered from: committed, and not expired"`
	Bytes          int64      `json:"bytes" doc:"their size, as the rows were streamed"`
	OldestCachedAt *time.Time `json:"oldest_cached_at,omitempty" doc:"when the oldest of those results was read from the warehouse. Absent without any."`
	NewestCachedAt *time.Time `json:"newest_cached_at,omitempty" doc:"when the newest of those results was read from the warehouse. Absent without any."`
	Expired        Expired    `json:"expired" doc:"results no query uses any more, expired, cleaned or abandoned, whose files are deleted by the next sweep"`
	Writing        int        `json:"writing" doc:"results being written now, by queries still running"`
}

QueryCacheContents are what the query cache holds.

type QueryCacheSelector

type QueryCacheSelector struct {
	DataSource string `json:"data_source,omitempty" doc:"entries of queries run on this data source"`
	Dataset    string `json:"dataset,omitempty" doc:"entries of queries run against this dataset"`
}

QueryCacheSelector selects the query cache's entries by their tags (docs/designs/query-cache.md#tags).

type QueryCacheSettings

type QueryCacheSettings struct {
	DefaultDuration string `` /* 136-byte string literal not displayed */
	MaxDuration     string `` /* 161-byte string literal not displayed */
	Namespace       string `json:"namespace,omitempty" doc:"the subfolder of canal-lake's storage the cache's files go in (ANFRA_CACHE_QUERY_NAMESPACE)"`
}

QueryCacheSettings are the query cache's settings that are set.

type QueryCacheStatus

type QueryCacheStatus struct {
	State    querycache.State    `` /* 325-byte string literal not displayed */
	Folder   string              `` /* 193-byte string literal not displayed */
	Problem  string              `json:"problem,omitempty" doc:"what's wrong with the cache, when it is incompatible or unavailable"`
	Reason   string              `json:"reason,omitempty" doc:"what turns the cache off, when it is disabled"`
	Settings *QueryCacheSettings `json:"settings,omitempty" doc:"the settings the cache runs with, those that are set"`
	Contents *QueryCacheContents `json:"contents,omitempty" doc:"what the cache holds, when it is ready"`
}

QueryCacheStatus is the query cache's state, and what it holds when it can be read.

type QueryFreed

type QueryFreed struct {
	Entries int   `json:"entries" doc:"how many results' files were deleted"`
	Bytes   int64 `json:"bytes" doc:"their size, in bytes"`
}

QueryFreed is what a clean's sweep deleted.

Jump to

Keyboard shortcuts

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