Documentation
¶
Overview ¶
Package cache provides generic cache. It is used to store values by key and retrieve them later.
Index ¶
Constants ¶
const ( // RunCmdCacheContextKey is the context key used to store and retrieve the run command cache RunCmdCacheContextKey ctxKey = iota // RepoRootCacheContextKey is the context key for the repo-root cache. RepoRootCacheContextKey )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cache ¶
Cache - generic cache implementation
func ContextCache ¶ added in v0.66.3
ContextCache returns cache from the context. If the cache is nil, it creates a new instance.
type ExpiringCache ¶
type ExpiringCache[V any] struct { Cache map[string]ExpiringItem[V] Mutex *sync.RWMutex Name string }
ExpiringCache - cache with items with expiration time
func NewExpiringCache ¶
func NewExpiringCache[V any](name string) *ExpiringCache[V]
NewExpiringCache - create new cache with generic type V
type ExpiringItem ¶
ExpiringItem - item with expiration time
type RepoRootCache ¶ added in v1.0.4
type RepoRootCache struct {
// contains filtered or unexported fields
}
RepoRootCache stores git repository roots and answers prefix-containment queries. Roots are kept sorted by descending length so Lookup yields the deepest matching root for paths inside nested repositories.
func ContextRepoRootCache ¶ added in v1.0.4
func ContextRepoRootCache(ctx context.Context, key any) *RepoRootCache
ContextRepoRootCache returns the RepoRootCache stored on the context, or a fresh detached instance if none is present so callers do not need to nil-check.
func NewRepoRootCache ¶ added in v1.0.4
func NewRepoRootCache(name string) *RepoRootCache
NewRepoRootCache constructs an empty RepoRootCache. The name is used as a prefix for telemetry counters.
func (*RepoRootCache) Add ¶ added in v1.0.4
func (c *RepoRootCache) Add(ctx context.Context, root string)
Add records root as a known repository root. Inserts are ordered by descending length so Lookup's first match is the deepest. Duplicates are ignored.
func (*RepoRootCache) BeginResolve ¶ added in v1.0.4
func (c *RepoRootCache) BeginResolve()
BeginResolve serializes callers that are about to perform the external lookup whose result they will Add. Callers must Lookup again after BeginResolve returns so a concurrent populate is observed before running the external resolver. EndResolve releases the lock.
The lock is independent of the cache's read/write mutex; it is held across the external call so concurrent misses collapse to a single resolution.
func (*RepoRootCache) EndResolve ¶ added in v1.0.4
func (c *RepoRootCache) EndResolve()
EndResolve releases the lock taken by BeginResolve.
func (*RepoRootCache) Len ¶ added in v1.0.4
func (c *RepoRootCache) Len() int
Len returns the number of cached roots.