Documentation
¶
Overview ¶
Package cache provides performance acceleration for bearer token validation using GoModularAuth's core cache adapter.
The database adapter remains the source of truth at all times; Cache is derived and ephemeral. Cache keys are strictly derived from cryptographic token hashes or IDs, never from plaintext secrets.
Index ¶
- Constants
- type Cache
- func (c *Cache) Available() bool
- func (c *Cache) DeleteByHash(ctx context.Context, tokenHash string) error
- func (c *Cache) DeleteByID(ctx context.Context, id string) error
- func (c *Cache) GetByHash(ctx context.Context, tokenHash string) (*CachedToken, error)
- func (c *Cache) Set(ctx context.Context, record *CachedToken, ttl time.Duration) error
- type CachedToken
Constants ¶
const (
// SubNamespace is the plugin sub-namespace within GoModularAuth cache keys.
SubNamespace = "bearer"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache wraps the core cache adapter for bearer token lookups.
func (*Cache) DeleteByHash ¶
DeleteByHash invalidates the cached record by token hash.
func (*Cache) DeleteByID ¶
DeleteByID invalidates cache entries associated with the token ID.
type CachedToken ¶
type CachedToken struct {
ID string `json:"id"`
TokenHash string `json:"token_hash"`
Subject string `json:"subject"`
PrincipalType string `json:"principal_type"`
Scopes []string `json:"scopes"`
Metadata map[string]string `json:"metadata,omitempty"`
ExpiresAt time.Time `json:"expires_at"`
RevokedAt *time.Time `json:"revoked_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
CachedToken represents the cached attributes of a bearer token.
func (*CachedToken) Active ¶
func (r *CachedToken) Active(now time.Time) bool
Active reports whether the token is neither expired nor revoked.
func (*CachedToken) Expired ¶
func (r *CachedToken) Expired(now time.Time) bool
Expired reports whether the token has expired relative to the given time.
func (*CachedToken) HasScope ¶
func (r *CachedToken) HasScope(scope string) bool
HasScope reports whether the record contains the specified scope.
func (*CachedToken) Revoked ¶
func (r *CachedToken) Revoked() bool
Revoked reports whether the token has been marked as revoked.