cache

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheDir

func CacheDir() (string, error)

CacheDir returns the default cache directory path (~/.grant/cache/).

func Get

func Get[T any](s *Store, key string, dst *T) bool

Get reads a cached value for key into dst. Returns true on hit, false on miss/expiry/error.

func Invalidate

func Invalidate(s *Store, key string)

Invalidate removes a cached entry by key.

func Set

func Set[T any](s *Store, key string, value T) error

Set writes a value to the cache under key. Creates the directory if needed.

Types

type CachedEligibilityLister

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

CachedEligibilityLister decorates eligibility listers with file-based caching. It implements both EligibilityLister and GroupsEligibilityLister.

func NewCachedEligibilityLister

func NewCachedEligibilityLister(
	cloudInner EligibilityLister,
	groupsInner GroupsEligibilityLister,
	store *Store,
	refresh bool,
	log Logger,
) *CachedEligibilityLister

NewCachedEligibilityLister creates a new caching decorator. Either inner may be nil if that type of listing is not needed. When refresh is true, the cache read is bypassed but the API response is still cached. Logger is optional — pass nil for silent operation.

func (*CachedEligibilityLister) ListEligibility

ListEligibility checks the cache first, then falls through to the inner lister.

func (*CachedEligibilityLister) ListGroupsEligibility

func (c *CachedEligibilityLister) ListGroupsEligibility(ctx context.Context, csp models.CSP) (*models.GroupsEligibilityResponse, error)

ListGroupsEligibility checks the cache first, then falls through to the inner lister.

type EligibilityLister

type EligibilityLister interface {
	ListEligibility(ctx context.Context, csp models.CSP) (*models.EligibilityResponse, error)
}

EligibilityLister mirrors cmd.eligibilityLister to avoid import cycles.

type GroupsEligibilityLister

type GroupsEligibilityLister interface {
	ListGroupsEligibility(ctx context.Context, csp models.CSP) (*models.GroupsEligibilityResponse, error)
}

GroupsEligibilityLister mirrors cmd.groupsEligibilityLister to avoid import cycles.

type Logger

type Logger interface {
	Info(msg string, v ...interface{})
}

Logger interface for verbose output — satisfied by *common.IdsecLogger.

type Store

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

Store manages a directory of JSON cache files with TTL expiry.

func NewStore

func NewStore(dir string, ttl time.Duration) *Store

NewStore creates a Store with the given directory and TTL.

Jump to

Keyboard shortcuts

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