cache

package
v0.125.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package cache stores scan results keyed by content hash so unchanged targets are not re-scanned. Keys come from plugin.ComputeCacheKey (a hex SHA, safe as a filename).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Get returns the cached report for key, or ok=false on miss/expiry.
	Get(key string) (sarif.Report, bool)
	// Put stores report under key.
	Put(key string, report sarif.Report) error
}

Cache stores and retrieves scan reports by key.

func ReadOnly added in v0.61.0

func ReadOnly(c Cache) Cache

ReadOnly returns a view of c that serves entries and stores none.

For a run whose results should not be trusted by the next one, a pull request from a fork being the case that matters, where the code deciding what the scan sees is not the code the cache is meant to describe. Reading stays useful: the entries already there were written by runs that were trusted.

A wrapper rather than a flag on Local so the guarantee is structural. A boolean checked inside Put is a boolean somebody can forget to check.

type Describer added in v0.125.0

type Describer interface {
	Describe() Description
}

Describer is a cache that can say where it is and how long it keeps things.

Optional, and asked for with a type assertion, so a cache that cannot answer stays a valid Cache and a caller that does not care is unaffected.

type Description added in v0.125.0

type Description struct {
	Dir      string
	TTL      time.Duration
	ReadOnly bool
}

Description is what a cache can say about itself, for a report that has to explain a reused finding to somebody reading it later.

The directory as it was given, not resolved and not probed. In CI it is usually an archive the platform restored under a key the pipeline chose, and whether that key still describes this tree is the pipeline's fact rather than the scan's. Naming the path is enough to tell a CI cache from a laptop's.

type Local

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

Local is a filesystem-backed cache with optional TTL expiry. Safe for concurrent use.

func NewLocal

func NewLocal(dir string, ttl time.Duration) *Local

NewLocal returns a cache storing entries under dir. A ttl of 0 disables expiry.

func (*Local) Describe added in v0.125.0

func (l *Local) Describe() Description

Describe reports where this cache is and how long it keeps entries.

func (*Local) Get

func (l *Local) Get(key string) (sarif.Report, bool)

Get returns the cached report for key, missing on absence, unreadable data, or expiry.

func (*Local) GetStamped added in v0.125.0

func (l *Local) GetStamped(key string) (sarif.Report, time.Time, bool)

GetStamped returns the cached report for key and when it was written.

func (*Local) Put

func (l *Local) Put(key string, report sarif.Report) error

Put stores report under key with the current timestamp.

type Memory

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

Memory is a process-lifetime in-memory cache (no TTL). Safe for concurrent use.

func NewMemory

func NewMemory() *Memory

NewMemory returns an empty in-memory cache.

func (*Memory) Get

func (c *Memory) Get(key string) (sarif.Report, bool)

Get returns the cached report for key.

func (*Memory) Put

func (c *Memory) Put(key string, report sarif.Report) error

Put stores report under key.

type Noop

type Noop struct{}

Noop is a cache that stores nothing and always misses.

func (Noop) Get

func (Noop) Get(string) (sarif.Report, bool)

Get always misses.

func (Noop) Put

func (Noop) Put(string, sarif.Report) error

Put discards the report.

type StampedGetter added in v0.125.0

type StampedGetter interface {
	GetStamped(key string) (report sarif.Report, storedAt time.Time, ok bool)
}

StampedGetter is a cache that reports when an entry was written, as well as what it holds.

Age is the difference between reusing an hour-old answer and a day-old one, and the entry knows it. Get throws it away, and widening Get would break every implementation for the one caller that wants it.

Jump to

Keyboard shortcuts

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