cache

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package cache is a small TTL cache with single-flight refresh, used for upstream list results.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache maps string keys to values with per-entry TTLs.

func New

func New() *Cache

New returns an empty cache.

func (*Cache) GetOrFill

func (c *Cache) GetOrFill(ctx context.Context, key string, ttl time.Duration, fill func(context.Context) (any, error)) (any, error)

GetOrFill returns the cached value for key, or runs fill (once across concurrent callers) and caches its result for ttl. ttl <= 0 bypasses the cache entirely.

func (*Cache) Invalidate

func (c *Cache) Invalidate(prefix string)

Invalidate drops all entries whose key has the given prefix.

Jump to

Keyboard shortcuts

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