Skip to content

Conversation

@devin-ai-integration
Copy link

Implement LRU Caching for OpenID Configuration Discovery

Summary

Optimizes the get_discovery_doc function by adding LRU caching to eliminate redundant HTTP requests to .well-known/openid_configuration endpoints. Since OpenID configuration is stable and rarely changes, this reduces latency and potential failure points when creating multiple AuthClient instances.

Key Changes:

  • Added @lru_cache(maxsize=128) decorator to get_discovery_doc function
  • Removed session parameter - function now always uses requests.get directly
  • Updated AuthClient.__init__ to call function without session parameter
  • Fixed test that was affected by cache interference with mocking

Review & Testing Checklist for Human

High Priority (3 items):

  • Verify caching works: Create multiple AuthClient instances with same environment and confirm only one HTTP request is made to discovery endpoint
  • Test environment isolation: Confirm that 'sandbox' and 'production' environments are cached separately
  • Run full test suite: Ensure no other tests have cache interference issues similar to the one fixed

Notes

  • LRU cache is thread-safe per Python documentation
  • Cache size of 128 should handle typical usage patterns (few environments × occasional cache eviction)
  • Previous session reuse for connection pooling is lost, but mitigated by caching the entire response
  • Cache will persist until process restart or manual clearing - discovery endpoint changes won't be picked up automatically

Link to Devin run: https://app.devin.ai/sessions/b279b98117be48f9b5f30414a34ea9ea
Requested by: @abhay-codeium

- Add @lru_cache(maxsize=128) decorator to get_discovery_doc function
- Remove session parameter from function signature and implementation
- Update function to always use requests.get directly
- Update AuthClient.__init__ to call get_discovery_doc without session parameter
- Fix test to clear cache before mocking to prevent cache interference

This optimization eliminates redundant HTTP requests to .well-known/openid_configuration
endpoint and reduces latency for subsequent AuthClient instantiations.

Co-Authored-By: abhay.aggarwal@codeium.com <abhay.aggarwal@windsurf.com>
@devin-ai-integration
Copy link
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

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