cache

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT, MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTTL = 5 * time.Minute

DefaultTTL is the default cache duration for policy evaluation decisions.

Variables

This section is empty.

Functions

func BuildKey

func BuildKey(principalSubject, principalType, organization, resType, resID, action string) string

BuildKey constructs a namespaced cache key for an evaluation request.

Types

type Cache

type Cache interface {
	GetDecision(ctx context.Context, key string) (*CachedDecision, bool, error)
	SetDecision(ctx context.Context, key string, decision *CachedDecision, ttl time.Duration) error
	InvalidatePrincipal(ctx context.Context, principalSubject string) error
	InvalidateResource(ctx context.Context, resourceType, resourceID string) error
	InvalidateAll(ctx context.Context) error
}

Cache defines the semantic contract for caching authorization decisions.

type CachedDecision

type CachedDecision struct {
	Effect    string         `json:"effect"`
	Reason    string         `json:"reason,omitempty"`
	Challenge map[string]any `json:"challenge,omitempty"`
	PolicyID  string         `json:"policy_id,omitempty"`
	CachedAt  time.Time      `json:"cached_at"`
}

CachedDecision is the stored authorization decision payload.

type CoreCacheAdapter

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

CoreCacheAdapter implements Cache using the shared GoModularAuth Core Cache.

func NewCoreCacheAdapter

func NewCoreCacheAdapter(c corecache.Cache, defaultTTL time.Duration) *CoreCacheAdapter

func (*CoreCacheAdapter) GetDecision

func (a *CoreCacheAdapter) GetDecision(ctx context.Context, key string) (*CachedDecision, bool, error)

func (*CoreCacheAdapter) InvalidateAll

func (a *CoreCacheAdapter) InvalidateAll(ctx context.Context) error

func (*CoreCacheAdapter) InvalidatePrincipal

func (a *CoreCacheAdapter) InvalidatePrincipal(ctx context.Context, principalSubject string) error

func (*CoreCacheAdapter) InvalidateResource

func (a *CoreCacheAdapter) InvalidateResource(ctx context.Context, resourceType, resourceID string) error

func (*CoreCacheAdapter) SetDecision

func (a *CoreCacheAdapter) SetDecision(ctx context.Context, key string, decision *CachedDecision, ttl time.Duration) error

type MemoryCache

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

MemoryCache provides an in-memory thread-safe cache for policy evaluations.

func NewMemoryCache

func NewMemoryCache(ttl time.Duration) *MemoryCache

func (*MemoryCache) GetDecision

func (m *MemoryCache) GetDecision(_ context.Context, key string) (*CachedDecision, bool, error)

func (*MemoryCache) InvalidateAll

func (m *MemoryCache) InvalidateAll(_ context.Context) error

func (*MemoryCache) InvalidatePrincipal

func (m *MemoryCache) InvalidatePrincipal(_ context.Context, principalSubject string) error

func (*MemoryCache) InvalidateResource

func (m *MemoryCache) InvalidateResource(_ context.Context, resourceType, resourceID string) error

func (*MemoryCache) SetDecision

func (m *MemoryCache) SetDecision(_ context.Context, key string, decision *CachedDecision, ttl time.Duration) error

Jump to

Keyboard shortcuts

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