cache

package
v0.3.111 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const ProfileNotAvailableErr = "profile not available"

ProfileNotAvailableErr is a sentinel error message used to indicate that a profile is not yet available. This error is NOT cached, allowing retry when profile becomes available. After the cache layer, this error should be converted to a default value (e.g., false) to allow rule evaluation to continue without failing.

Variables

This section is empty.

Functions

func ConvertProfileNotAvailableErrToBool added in v0.3.9

func ConvertProfileNotAvailableErrToBool(val ref.Val, defaultVal bool) ref.Val

ConvertProfileNotAvailableErrToBool converts a "profile not available" error to a boolean value. This should be called AFTER the cache layer to ensure the error is not cached, but the rule evaluation can continue with a default value.

func HashForContainerProfile added in v0.3.111

func HashForContainerProfile(oc objectcache.ObjectCache) func([]ref.Val) string

HashForContainerProfile returns a function that extracts the SpecHash of the projected profile for the containerID in values[0]. Passing this to WithCache ensures cached results are invalidated whenever the projection spec changes.

func IsProfileNotAvailableErr added in v0.3.9

func IsProfileNotAvailableErr(val ref.Val) bool

IsProfileNotAvailableErr checks if the given value is a "profile not available" error.

func NewProfileNotAvailableErr added in v0.3.9

func NewProfileNotAvailableErr(format string, args ...any) ref.Val

NewProfileNotAvailableErr creates a new "profile not available" error. This error will NOT be cached, allowing the function to be re-evaluated when the profile becomes available.

Types

type CelFunction

type CelFunction func(...ref.Val) ref.Val

type FunctionCache

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

func NewFunctionCache

func NewFunctionCache(config FunctionCacheConfig) *FunctionCache

func (*FunctionCache) ClearCache

func (fc *FunctionCache) ClearCache()

func (*FunctionCache) GetCacheStats

func (fc *FunctionCache) GetCacheStats() (size int)

func (*FunctionCache) WithCache

func (fc *FunctionCache) WithCache(fn CelFunction, functionName string, extraKeyFn ...func([]ref.Val) string) CelFunction

WithCache wraps fn with an LRU result cache keyed by functionName + arguments. extraKeyFn, if provided, is called with the argument slice and its return value is appended to the key — use HashForContainerProfile to invalidate on spec changes.

type FunctionCacheConfig

type FunctionCacheConfig struct {
	MaxSize int           `mapstructure:"maxSize"`
	TTL     time.Duration `mapstructure:"ttl"`
}

func DefaultFunctionCacheConfig

func DefaultFunctionCacheConfig() FunctionCacheConfig

Jump to

Keyboard shortcuts

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