Skip to content

fix: Redis token cache bug fixes and docs#32

Merged
koljahuang merged 4 commits intomainfrom
fix/redis-token-cache-cleanup
Apr 21, 2026
Merged

fix: Redis token cache bug fixes and docs#32
koljahuang merged 4 commits intomainfrom
fix/redis-token-cache-cleanup

Conversation

@koljahuang
Copy link
Copy Markdown
Contributor

Summary

  • Fix AttributeError on token.allowed_models in CachedTokenService that silently broke Redis token caching (cache never worked)
  • Add fallback warning log in _validate_token_with_cache for easier debugging
  • Remove dead validate_token_for_model dependency (referenced non-existent allowed_models field, unused)
  • Use module-level logger instead of inline import logging
  • Add Redis token cache documentation to performance and security docs (EN + ZH)

Root cause

token_cache.py referenced token.allowed_models which was removed from the APIToken model when model restrictions moved to a separate Model relationship. The AttributeError was caught by except Exception and silently fell back to DB every time.

Test plan

  • Verified in production pod: token validation writes to Redis (token:{hash} key with TTL 300s)
  • Subsequent requests hit Redis cache (no new DB query)
  • Confirm revoke/delete clears cache immediately
  • Confirm Redis unavailable gracefully falls back to DB

Chao Huang added 3 commits April 21, 2026 09:20
_cache_token accessed token.allowed_models which no longer exists on
APIToken (model restrictions moved to models relationship). This caused
AttributeError silently caught by the fallback, making Redis cache
never actually work. Also add warning log in the fallback path.
… docs

Add Redis cache layer description (TTL, graceful degradation, cache
invalidation, key format) to performance docs. Update key files lists
in security docs to include redis.py and token_cache.py.
Move logging import to module level, drop exc_info from hot-path
fallback warning, remove unused validate_token_for_model that
referenced non-existent allowed_models field.
@koljahuang koljahuang mentioned this pull request Apr 21, 2026
@koljahuang koljahuang merged commit 3093b9d into main Apr 21, 2026
11 checks passed
@koljahuang koljahuang deleted the fix/redis-token-cache-cleanup branch April 21, 2026 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant