cache

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package cache provides secret caching functionality using the system keyring. Secrets are cached with a configurable TTL to reduce API calls to providers.

Index

Constants

View Source
const (
	// KeyringService is the service name used for keyring storage
	KeyringService = "sstart-cache"
	// DefaultTTL is the default cache TTL (5 minutes)
	DefaultTTL = 5 * time.Minute
)

Variables

This section is empty.

Functions

func GenerateCacheKey

func GenerateCacheKey(providerID string, kind string, config map[string]interface{}) string

GenerateCacheKey generates a unique cache key based on provider configuration. The key is a hash of the provider kind, id, and configuration.

Types

type Cache

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

Cache provides caching functionality for secrets

func New

func New(opts ...Option) *Cache

New creates a new Cache instance

func (*Cache) CleanExpired

func (c *Cache) CleanExpired() error

CleanExpired removes all expired cache entries

func (*Cache) Clear

func (c *Cache) Clear() error

Clear removes all cached secrets

func (*Cache) ClearProvider

func (c *Cache) ClearProvider(cacheKey string) error

ClearProvider removes cached secrets for a specific provider

func (*Cache) Get

func (c *Cache) Get(cacheKey string) (map[string]string, bool)

Get retrieves cached secrets for a provider if they exist and are not expired

func (*Cache) GetTTL

func (c *Cache) GetTTL() time.Duration

GetTTL returns the configured TTL

func (*Cache) IsAvailable

func (c *Cache) IsAvailable() bool

IsAvailable returns whether the cache backend (keyring) is available

func (*Cache) Set

func (c *Cache) Set(cacheKey string, secrets map[string]string) error

Set stores secrets in the cache with the configured TTL. If keyring is not available, this is a no-op (returns nil).

func (*Cache) Stats

func (c *Cache) Stats() (total int, valid int, expired int)

Stats returns cache statistics

type CacheStore

type CacheStore struct {
	Providers map[string]*CachedSecrets `json:"providers"`
}

CacheStore represents the entire cache storage

type CachedSecrets

type CachedSecrets struct {
	Secrets   map[string]string `json:"secrets"`
	ExpiresAt time.Time         `json:"expires_at"`
	CachedAt  time.Time         `json:"cached_at"`
}

CachedSecrets represents cached secrets with metadata

type Option

type Option func(*Cache)

Option is a functional option for configuring the Cache

func WithTTL

func WithTTL(ttl time.Duration) Option

WithTTL sets a custom TTL for the cache

Jump to

Keyboard shortcuts

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