cache

package
v4.15.3 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: AGPL-3.0 Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheBaseDir

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

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 NewDiskCacheAt

func NewDiskCacheAt(dir string) (*DiskCache, error)

NewDiskCacheAt creates a disk cache rooted at dir (tests and tools).

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