cache

package
v1.85.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DiskCache

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

DiskCache stores charts on disk with TTL expiration and concurrency safety.

func NewDiskCache

func NewDiskCache(opts ...Option) (*DiskCache, error)

NewDiskCache creates a new cache instance using functional options. It starts a background goroutine for cleanup automatically.

func (*DiskCache) Clear

func (c *DiskCache) Clear() error

Clear removes all cached files.

func (*DiskCache) Get

func (c *DiskCache) Get(uri, version string) (io.ReadCloser, bool)

Get retrieves a chart stream from the disk cache. It returns an io.ReadCloser which MUST be closed by the caller to avoid file handle leaks. Memory Impact: Low (Streaming).

func (*DiskCache) Set

func (c *DiskCache) Set(uri, version string, source io.Reader) error

Set streams a chart from the source Reader to the disk cache. It uses atomic writes (write to temp -> rename) to ensure integrity.

func (*DiskCache) Stop

func (c *DiskCache) Stop()

Stop halts the background cleanup goroutine to prevent leaks. It is idempotent and safe to call concurrently: a bare close(c.stopCh) panics with "close of closed channel" on the second call, which turned a harmless double-cleanup into a process crash. Stop is reached from the helm client's Close(), and callers legitimately end up invoking that more than once — a deferred close on a client variable that was reassigned, a Close in both an error path and a defer, or two goroutines shutting down together. Failing loudly there punished correct cleanup, so callers were discouraged from closing at all, which is how the cleanup goroutine leaked in the first place (krateo-platformops/core-provider#99). TTLCache already guards its stop channel this way; this makes DiskCache consistent with it.

type Option

type Option func(*DiskCache)

Option defines the functional pattern for configuration.

func WithCleanupInterval

func WithCleanupInterval(d time.Duration) Option

WithCleanupInterval sets how often the cache scans for expired items. Default: 1 Hour

func WithDir

func WithDir(dir string) Option

WithDir sets the cache directory. Default: os.TempDir()/helm-chart-cache

func WithTTL

func WithTTL(d time.Duration) Option

WithTTL sets the time-to-live for cached items. Default: 24 Hours

Jump to

Keyboard shortcuts

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