Repository navigation
Add in-memory caching for authenticated user info - #8
Conversation
- Add cachetools TTLCache with 20-second TTL for auth responses - Cache authenticated user info to reduce OpenHands API calls - 20s TTL ensures revoked keys stop working within 20 seconds - Supports smooth integration test execution without rate limits - No external infrastructure (Redis) required for prototyping Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
all-hands-bot
left a comment
There was a problem hiding this comment.
🟡 Acceptable - Pragmatic caching solution with solid fundamentals. One important testing gap to address.
KEY INSIGHT: The core logic is clean and solves a real problem (rate limits), but the TTL expiration test doesn't actually verify the mechanism it claims to test.
- Change AUTH_CACHE_TTL_SECONDS to float (20.0) for consistency - Add debug log for cache misses to match cache hit logging - Fix TTL test to actually test TTL expiration using short TTL cache Co-authored-by: openhands <openhands@all-hands.dev>
all-hands-bot
left a comment
There was a problem hiding this comment.
🟢 Good taste - Pragmatic caching solution that solves a real problem simply.
KEY INSIGHT: This is exactly what prototype infrastructure should look like: transparent caching with a sensible TTL, clean logic flow with no special cases, and tests that verify the actual mechanisms (TTL expiration, failure handling). Previous review feedback has been properly addressed. The 20-second security trade-off is documented and reasonable. Ship it.
Summary
Adds a 20-second in-memory cache for authenticated user information in the auth middleware using
cachetools.TTLCache.Changes
cachetoolsdependency for TTLCache functionalityauthenticate_requestto check cache before making OpenHands API callsclear_auth_cache()helper for testingRationale
Why 20 seconds TTL?
Why cachetools instead of Redis?
How it works