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: 9 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTTL = 5 * time.Minute

DefaultTTL is the default cache duration for authorization decisions.

Variables

This section is empty.

Functions

func BuildKey

func BuildKey(principal auth.Principal, permission string, resType, resID, orgID, serviceID string) string

BuildKey constructs a namespaced cache key for an authorization query.

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
	InvalidateAll(ctx context.Context) error
}

Cache defines the semantic contract for caching authorization decisions.

type CachedDecision

type CachedDecision struct {
	Allowed     bool      `json:"allowed"`
	Reason      string    `json:"reason,omitempty"`
	MatchedRole string    `json:"matched_role,omitempty"`
	Permission  string    `json:"permission"`
	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 adapter.

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) 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 a fast, standalone thread-safe in-memory cache for RBAC 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) 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