Documentation
¶
Overview ¶
Package clientauthcache caches successful client_secret verifications (Argon2id), so hot endpoints do not pay the Argon2 cost on every request. The key is the client_id and the value binds the verified snapshot to the sha256 of the presented secret. Entries expire after a TTL, failures are never cached, and the cache is a bounded LRU. Invalidate must run on every secret rotation or deletion, and the plaintext secret is never stored.
Index ¶
Constants ¶
const DefaultMaxEntries = 1024
DefaultMaxEntries bounds the cache so probing many synthetic client_ids cannot exhaust memory (about 1 MiB at the default).
const DefaultTTL = 5 * time.Minute
DefaultTTL bounds how long a verified entry stays usable. It stays within the introspection cache horizon, so a revoked secret does not linger.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[V any] struct { // contains filtered or unexported fields }
Cache is a bounded LRU keyed by client_id holding the verified client snapshot and the sha256 of the secret that authorized it. Every public method holds the mutex for its whole critical section, so operations stay O(1).
func (*Cache[V]) Get ¶
Get returns the cached value only when the entry exists, has not expired, and the presented secret's sha256 matches. A hit moves the entry to the LRU front. On a miss the caller must run the slow Argon2 verify.
func (*Cache[V]) Invalidate ¶
Invalidate drops the entry for clientID. Any path that rotates or revokes client_secret_hash must call it. Safe on a missing key.