You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* feat(cache): add configurable token verification cache layer
Add an optional cache layer (memory/Redis/Redis-aside) for token
verification to reduce database queries on the ValidateToken hot path.
The cache reuses the existing generic Cache[T] infrastructure and is
disabled by default (TOKEN_CACHE_ENABLED=false).
Key design decisions:
- Only ValidateToken uses the cache; IntrospectToken (RFC 7662) always
hits the database for authoritative real-time state
- Single-token revocations immediately invalidate the cache
- Bulk revocations (by user, by token family) collect hashes before
deletion and invalidate each cached entry
- Cache invalidation happens after transaction commit, not inside, to
avoid premature eviction on rollback
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* test(cache): add cache invalidation tests and fix silent error handling
- Add TestRevokeTokenByID_CacheInvalidated for ID-based revocation
- Add TestEnableToken_CacheInvalidated for disable/enable cycle
- Add TestRevokeAllUserTokens_CacheInvalidated for bulk eviction
- Add TestRefreshAccessToken_RotationMode_CacheInvalidated for rotation
- Add TestRevokeTokenFamily_CacheInvalidated for replay detection
- Log errors from GetActiveTokenHashesByFamilyID instead of discarding
- Log errors from GetTokensByUserID in RevokeAllUserTokens
- Add safe hash truncation in invalidateTokenCache error log
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix(cache): only invalidate cache after successful revocation
- Restructure RevokeAllUserTokens to skip cache invalidation when
DB revocation fails, preventing stale cache entries on error
- Clarify .env.example comment about cache TTL behavior during
bulk revocation to reflect actual per-token invalidation logic
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix(cache): graceful fallback on cache errors and strict token lookup
- Fall back to direct DB lookup when cache backend fails (e.g. Redis
unavailable) instead of rejecting valid tokens
- Return error from GetAccessTokenByID in RevokeTokenByStatus to prevent
cache entries from becoming stale when token lookup fails
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* style(cache): fix golines and testifylint issues
- Break long log.Printf lines to satisfy golines max line length
- Use require.Error instead of assert.Error for error assertions
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* test(cache): add tokeninfo integration tests and validation benchmarks
- Add end-to-end handler tests verifying cache population, revoke/disable
invalidation, and nil-cache regression for /oauth/tokeninfo
- Add benchmarks comparing ValidateToken with and without memory cache
(4.4x throughput improvement on cache hit path)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refactor(test): simplify token cache tests
- Remove redundant WHAT-comments, keep only WHY-comments
- Deduplicate NewTokenService calls using core.Cache interface variable
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
0 commit comments