cache

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 23, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found in cache")

ErrNotFound is returned when a result isn't found in the cache

Functions

func NewScorecardClient

func NewScorecardClient(ca Cache, client scorecard.Client) scorecard.Client

NewScorecardClient returns a scorecard client that caches scores from another client

Types

type Cache

type Cache interface {
	// GetResult retrieves a scorecard result from the cache
	GetResult(ctx context.Context, repository string) (*models.ScorecardResult, error)

	// PutResult inserts a score into the cache
	PutResult(ctx context.Context, repository string, result *models.ScorecardResult) error
}

Cache caches results

func NewSqliteCache

func NewSqliteCache(dbDir string, opts ...Option) (Cache, error)

NewSqliteCache returns a cache implementation that stores scorecard scores in a local sqlite database

type Option

type Option func(o *options)

Option is a functional option that configures a cache

func WithDuration

func WithDuration(d time.Duration) Option

WithDuration is a functional option that configures the amount of time until an item in the cache is invalidated

type ScorecardClient

type ScorecardClient struct {
	scorecard.Client
	// contains filtered or unexported fields
}

ScorecardClient wraps another scorecard client, caching the scores it retrieves

func (*ScorecardClient) GetResult

func (c *ScorecardClient) GetResult(ctx context.Context, repository string) (*models.ScorecardResult, error)

GetResult attempts to get the scorecard result from the cache. Failing that it will get the scorecard result from the wrapped client and cache it for next time.

Jump to

Keyboard shortcuts

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