Documentation
¶
Index ¶
- Constants
- func PolicyNames() []string
- func RefreshRequested(ctx context.Context) bool
- func Register(cache Cache)
- func WithObserver(ctx context.Context, observe Observer) context.Context
- func WithRefresh(ctx context.Context) context.Context
- type Cache
- type CacheClass
- type CacheMetadata
- type CachePolicy
- type CacheState
- type CacheStats
- type FlushOptions
- type FlushResult
- type FlushedCache
- type GetOptions
- type Memo
- type MemoOptions
- type Observation
- type Observer
- type ObserverKey
- type RefreshKey
- type Result
Constants ¶
const DefaultFillTimeout = 15 * time.Second
Variables ¶
This section is empty.
Functions ¶
func PolicyNames ¶
func PolicyNames() []string
PolicyNames lists the cache classes a caller may flush by name, so a UI can offer them instead of asking someone to type one.
func RefreshRequested ¶
RefreshRequested reports whether ctx asked for every lookup to rebuild.
func Register ¶
func Register(cache Cache)
Register adds a cache to the process-wide list. NewMemo calls it, so a memo is reachable the moment it exists and no call site has to remember.
func WithObserver ¶
WithObserver returns a context whose inspection lookups report to observe.
Installing a second observer replaces the first rather than chaining: the owner of a request context is the one party that knows what should hear about its lookups, and a hidden chain would let an inner scope leak observations to an outer one after it went out of scope.
Types ¶
type Cache ¶
type Cache interface {
Policy() CachePolicy
Stats() CacheStats
// Clear drops every entry and returns how many there were. Entries being
// filled right now are invalidated too, so the fill in flight cannot land
// afterwards and resurrect what was just dropped.
Clear() int
Invalidate(key string)
InvalidatePrefix(prefix string)
}
Cache is what a Memo looks like to something that does not know its value type — enough to describe it and to throw it away.
type CacheClass ¶
type CacheClass string
const ( CacheClassOpenSearchTargets CacheClass = "opensearch-targets" CacheClassSQLCatalog CacheClass = "sql-catalog" CacheClassOpenSearchFields CacheClass = "opensearch-fields" CacheClassOpenSearchDynamicMapping CacheClass = "opensearch-dynamic-mapping" CacheClassOpenSearchConcreteMapping CacheClass = "opensearch-concrete-mapping" CacheClassCardinality CacheClass = "column-cardinality" CacheClassFilterValues CacheClass = "filter-values" )
type CacheMetadata ¶
type CacheMetadata struct {
Policy string `json:"policy"`
State CacheState `json:"state"`
Cached bool `json:"cached"`
Refreshing bool `json:"refreshing,omitempty"`
LoadedAt time.Time `json:"loadedAt"`
FreshUntil time.Time `json:"freshUntil"`
LastChangedAt time.Time `json:"lastChangedAt"`
LastRefreshAttempt *time.Time `json:"lastRefreshAttempt,omitempty"`
LastRefreshError string `json:"lastRefreshError,omitempty"`
AgeMS int64 `json:"ageMs"`
RetryAfterMS int64 `json:"retryAfterMs,omitempty"`
UnchangedRefreshes int `json:"unchangedRefreshes,omitempty"`
}
type CachePolicy ¶
type CachePolicy struct {
Name string
InitialFreshFor time.Duration
MaximumFreshFor time.Duration
FillTimeout time.Duration
MaxEntries int
MaxWeight int
}
func Policy ¶
func Policy(class CacheClass) CachePolicy
type CacheState ¶
type CacheState string
const ( CacheStateFresh CacheState = "fresh" CacheStateStale CacheState = "stale" )
type CacheStats ¶
type CacheStats struct {
Policy string `json:"policy"`
Entries int `json:"entries"`
MaxEntries int `json:"maxEntries"`
Weight int `json:"weight"`
MaxWeight int `json:"maxWeight"`
// Filling counts loads in flight. A cache that is always filling is one
// whose freshness window is shorter than the thing it caches takes to build.
Filling int `json:"filling"`
// Oldest is when the least recently loaded entry was filled, and is zero for
// an empty cache.
Oldest time.Time `json:"oldest,omitempty"`
// FreshFor and MaxFreshFor are the policy's window, reported so a console can
// explain a stale read without a second lookup.
FreshForSeconds int64 `json:"freshForSeconds"`
MaxFreshForSeconds int64 `json:"maxFreshForSeconds"`
}
CacheStats describes one cache's occupancy against the ceilings its policy set — the two numbers that say whether it is doing anything and whether it is about to start evicting.
type FlushOptions ¶
FlushOptions narrows what a flush throws away. An empty Policy means every cache; an empty Key and Prefix mean every entry within the caches chosen.
type FlushResult ¶
type FlushResult struct {
Caches []FlushedCache `json:"caches"`
Entries int `json:"entries"`
}
FlushResult reports what was actually dropped, per cache.
Reported rather than assumed: a flush aimed at a key that was never cached looks identical to one that worked, and an operator who cannot tell the two apart will conclude the flush is broken.
func Flush ¶
func Flush(options FlushOptions) FlushResult
Flush drops matching entries and reports what went.
type FlushedCache ¶
type GetOptions ¶
type Memo ¶
type Memo[T any] struct { // contains filtered or unexported fields }
func NewMemo ¶
func NewMemo[T any](options MemoOptions[T]) *Memo[T]
func (*Memo[T]) Clear ¶
Clear drops every entry and returns how many there were.
Generations are bumped for entries being filled right now, so a fill already in flight cannot land afterwards and resurrect what was just dropped — which is the difference between a flush and a suggestion.
func (*Memo[T]) Invalidate ¶
func (*Memo[T]) InvalidatePrefix ¶
func (*Memo[T]) Policy ¶
func (m *Memo[T]) Policy() CachePolicy
Policy is the freshness and capacity contract this memo was built with.
func (*Memo[T]) Stats ¶
func (m *Memo[T]) Stats() CacheStats
Stats describes what the memo currently holds.
type MemoOptions ¶
type Observation ¶
type Observation struct {
// Policy is the cache class (see CacheClass), and Key the entry within it.
Policy string
Key string
// Elapsed is the wall time this caller waited. A cached read is ~0; a miss
// pays the whole fill, which is the number worth looking at.
Elapsed time.Duration
Cache CacheMetadata
// Err is the fill failure, if the caller got one. A stale entry served after
// a failed refresh reports the failure on Cache.LastRefreshError instead and
// leaves this empty — the caller was not failed, only served older facts.
Err error
}
Observation is one inspection-cache lookup as the caller experienced it.
type Observer ¶
type Observer func(Observation)
Observer receives every lookup made under a context it was installed on. It is called on the caller's goroutine, so it must not block.
func ObserverFrom ¶
ObserverFrom returns the observer installed on ctx, or nil.
type ObserverKey ¶
type ObserverKey struct{}
ObserverKey is the context key an observer is stored under.
Exported because the request contexts that install one are not plain context.Context — commons-db's Context sets values through its own WithValue and would have to be rebuilt around a stdlib child otherwise, losing the database handle and namespace it carries.
type RefreshKey ¶
type RefreshKey struct{}
RefreshKey marks a context whose inspection lookups must all rebuild rather than read what is cached.
Exported for the same reason ObserverKey is: the request contexts that set it are commons-db's Context, which carries a database handle and a namespace it would lose if it had to be rebuilt around a stdlib child.
It is deliberately per-request. GetOptions.Refresh already says "rebuild this one lookup" for a caller that knows which; this says "rebuild everything I read", which is what someone debugging a page wants and is still nobody else's problem — unlike flushing the cache, which is (see Flush).
type Result ¶
type Result[T any] struct { Value T Cache CacheMetadata }
Directories
¶
| Path | Synopsis |
|---|---|
|
Package opensearchinspect provides bounded, read-only OpenSearch metadata inspection.
|
Package opensearchinspect provides bounded, read-only OpenSearch metadata inspection. |
|
Package sqlinspect provides reusable, read-only SQL catalog inspection.
|
Package sqlinspect provides reusable, read-only SQL catalog inspection. |