cache

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package cache provides file-based caching with TTL expiry.

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 CleanupSessions added in v0.6.0

func CleanupSessions(s *Store, activeIDs []string) error

CleanupSessions removes entries for sessions not in the activeIDs list.

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 RecordSession added in v0.6.0

func RecordSession(s *Store, sessionID string, now time.Time) error

RecordSession stores the elevation timestamp for a session ID. It performs a read-modify-write on the session timestamps cache entry.

func SessionTimestamps added in v0.6.0

func SessionTimestamps(s *Store) map[string]time.Time

SessionTimestamps returns a map of sessionID -> elevatedAt for all tracked sessions. Entries older than maxSessionAge are filtered out. Returns an empty map on error.

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 CachedRolesLister added in v0.7.0

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

CachedRolesLister decorates an OnDemandRolesLister with file-based caching.

func NewCachedRolesLister added in v0.7.0

func NewCachedRolesLister(inner OnDemandRolesLister, store *Store, refresh bool, log Logger) *CachedRolesLister

NewCachedRolesLister creates a caching decorator for on-demand role discovery. When refresh is true, the cache read is bypassed but the API response is still cached.

func (*CachedRolesLister) ListOnDemandResources added in v0.7.0

ListOnDemandResources 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 OnDemandRolesLister added in v0.7.0

type OnDemandRolesLister interface {
	ListOnDemandResources(ctx context.Context, req scamodels.OnDemandRequest) ([]scamodels.OnDemandResource, error)
}

OnDemandRolesLister mirrors the service method for on-demand role discovery.

type SessionRecord added in v0.6.0

type SessionRecord struct {
	ElevatedAt time.Time `json:"elevated_at"`
}

SessionRecord stores the timestamp when a session was elevated.

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