versionedcache

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 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 Cache

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

Cache wraps a diskcache.Cache with a semver version index. It maintains a sorted (descending) list of versions per name+platform, kept in sync automatically via the diskcache OnEviction callback.

func New

func New(cacheDir string, maxSize int64, opts ...diskcache.CacheOption) (*Cache, error)

New creates a Cache backed by a bounded diskcache. The OnEviction callback is wired internally to keep the version index consistent when the diskcache evicts entries.

func (*Cache) BaseDir

func (vc *Cache) BaseDir() string

BaseDir returns the root directory of the underlying diskcache.

func (*Cache) Delete

func (vc *Cache) Delete(name, version, platform string) bool

Delete explicitly removes an entry from the diskcache. The version index is updated via the OnEviction callback.

func (*Cache) Latest

func (vc *Cache) Latest(name, platform string) (version string, ok bool)

Latest returns the highest cached semver version for a name+platform. Returns ok=false if nothing is indexed.

func (*Cache) Pin

func (vc *Cache) Pin(name, version, platform string) (path string, release func(), ok bool)

Pin marks a cache entry as in-use and returns its on-disk path. The entry cannot be evicted until the returned release function is called. The entry file can however be updated while holding the pin, in which case the path will point to the updated content. Returns ok=false if the entry is not in the cache.

func (*Cache) Set

func (vc *Cache) Set(name, version, platform string, data []byte) error

Set writes data into the diskcache and adds the version to the index.

func (*Cache) SetPin

func (vc *Cache) SetPin(name, version, platform string, data []byte) (string, func(), error)

SetPin writes data, pins the entry atomically, and updates the version index. The entry cannot be evicted until the returned release function is called.

func (*Cache) Versions

func (vc *Cache) Versions(name, platform string) []string

Versions returns all indexed versions for a name+platform, sorted descending. The returned slice is a copy.

func (*Cache) WarmUp

func (vc *Cache) WarmUp() error

WarmUp scans the cache directory for existing plugin binaries and populates both the diskcache LRU and the version index without reading file contents. Files are adopted into the LRU without triggering eviction — the cache may temporarily exceed maxSize. Eviction occurs naturally on the next Set call.

Jump to

Keyboard shortcuts

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