cache

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheBaseDir added in v1.10.0

func CacheBaseDir() (string, error)

CacheBaseDir returns the parent directory of all versioned cache dirs (~/.vulnetix/cache/vdb).

func CacheKey

func CacheKey(apiVersion, path string) string

CacheKey returns a filesystem-safe hex key for an API version + path.

func CleanOldCaches added in v1.10.0

func CleanOldCaches(cliVersion string) (int, error)

CleanOldCaches removes cache directories for CLI versions other than cliVersion. Also removes bare .json files left from the pre-versioned cache layout. Returns the number of entries removed. Errors are best-effort.

Types

type DiskCache

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

DiskCache stores HTTP responses on disk.

func NewDiskCache

func NewDiskCache(cliVersion string) (*DiskCache, error)

NewDiskCache creates a new disk cache rooted at ~/.vulnetix/cache/vdb/vX.Y.

func (*DiskCache) Clear

func (c *DiskCache) Clear() error

Clear removes all cached entries.

func (*DiskCache) Dir

func (c *DiskCache) Dir() string

Dir returns the cache directory path.

func (*DiskCache) Get

func (c *DiskCache) Get(key string) (*Entry, bool)

Get retrieves a cache entry. Returns (entry, true) on hit. A stale entry is still returned so callers can do conditional requests.

func (*DiskCache) Put

func (c *DiskCache) Put(key string, entry *Entry) error

Put writes a cache entry to disk atomically.

type Entry

type Entry struct {
	Body         []byte        `json:"body"`
	ETag         string        `json:"etag,omitempty"`
	LastModified string        `json:"lastModified,omitempty"`
	CachedAt     time.Time     `json:"cachedAt"`
	TTL          time.Duration `json:"ttl"`
}

Entry represents a cached HTTP response.

func (*Entry) IsFresh

func (e *Entry) IsFresh() bool

IsFresh returns true if the entry has not expired.

Jump to

Keyboard shortcuts

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