cache

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthCache

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

AuthCache provides caching for password verification results to avoid expensive argon2id re-computation on every request.

func NewAuthCache

func NewAuthCache(cfg AuthCacheConfig) *AuthCache

NewAuthCache creates a new authentication cache.

func (*AuthCache) Clear

func (c *AuthCache) Clear()

Clear removes all entries from the cache.

func (*AuthCache) Enabled

func (c *AuthCache) Enabled() bool

Enabled returns whether the cache is enabled.

func (*AuthCache) Stats

func (c *AuthCache) Stats() (int64, int64, int)

Stats returns cache statistics: hits, misses, and current size.

func (*AuthCache) VerifyKey added in v0.1.0

func (c *AuthCache) VerifyKey(ctx context.Context, keyID, plainKey, storedHash string) (bool, error)

VerifyKey verifies a key hash, using cache if available. keyID is used for logging only. This method is suitable for API keys and web session keys.

func (*AuthCache) VerifyPassword

func (c *AuthCache) VerifyPassword(ctx context.Context, userID, password, storedHash string) (bool, error)

VerifyPassword verifies a password, using cache if available. userID should be a unique identifier for the user (e.g., UID).

type AuthCacheConfig

type AuthCacheConfig struct {
	Enabled    bool
	TTLSeconds int
	MaxSize    int
}

AuthCacheConfig holds configuration for the auth cache.

type RevocationHandle added in v0.16.0

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

RevocationHandle is held by a live proxy session for as long as it relies on a particular grant. Its flag is flipped to true the instant that grant is revoked, so the session's per-command check and its limit watchdog observe the revocation without a database round-trip on every query.

All methods are nil-safe: a session that could not obtain a handle (e.g. a nil registry in a test) treats itself as never-revoked.

func (*RevocationHandle) Flag added in v0.16.0

func (h *RevocationHandle) Flag() *atomic.Bool

Flag exposes the underlying atomic flag so a limit watchdog can poll it cheaply (a single atomic load) alongside the byte/time checks. Returns nil for a nil handle, which downstream guards treat as "no revocation to watch".

func (*RevocationHandle) Revoked added in v0.16.0

func (h *RevocationHandle) Revoked() bool

Revoked reports whether the grant backing this handle has been revoked.

type RevocationRegistry added in v0.16.0

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

RevocationRegistry is an in-process fan-out from the API's grant-revoke path to the live proxy sessions that authenticated under those grants. It lets a revocation take effect on already-established connections — blocking their next query and tearing the session down — instead of only being consulted at connect time.

It carries no database state: it maps a grant UID to the set of live session handles depending on it. Revoke flips their flags; the sessions' existing LimitGuard watchdog and checkQuotas paths do the rest.

func NewRevocationRegistry added in v0.16.0

func NewRevocationRegistry() *RevocationRegistry

NewRevocationRegistry creates an empty registry.

func (*RevocationRegistry) Deregister added in v0.16.0

func (r *RevocationRegistry) Deregister(grantUID uuid.UUID, h *RevocationHandle)

Deregister drops a handle previously returned by Register. Safe to call with a nil registry/handle or a handle that was never registered.

func (*RevocationRegistry) Register added in v0.16.0

func (r *RevocationRegistry) Register(grantUID uuid.UUID) *RevocationHandle

Register records a live session that relies on grantUID and returns its handle. Deregister must be called when the session ends. Calling on a nil registry, or with uuid.Nil, still returns a usable (never-revoked) handle so callers never have to nil-check the result.

func (*RevocationRegistry) Revoke added in v0.16.0

func (r *RevocationRegistry) Revoke(grantUID uuid.UUID) int

Revoke flips the revoked flag on every live session bound to grantUID and returns the number of sessions signaled. Safe to call for a grant with no live sessions (returns 0). It does not deregister the handles — the sessions tear themselves down and Deregister on the way out.

Jump to

Keyboard shortcuts

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