-
Notifications
You must be signed in to change notification settings - Fork 72
Feat: Added Cache Implementation #221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The following is from our gemini code review gem Code ReviewThis pull request introduces a much-needed caching layer to the
SummaryTop three areas for improvement:
Confidence Rating: High I am highly confident in this assessment. The identified issues, particularly the concurrency problems, are based on well-established Java programming patterns. |
…th0/jwks-rsa-java into sdk-6221-improve-cache-design
|
Thank you for the brief summary, I have addressed the changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
A/C to this, cache-control headers for
jwk_urlreturn a default maxAge of 15s. We can take this as the default value of a configurableJWKs_refresh_intervalfor de-duplicating N/W calls. -
Why are we coupling local
findKeywith a network call on the same thread? Write operations are done on shared cache, why not delegate network calls to a dedicated network thread(pool), that uses a single-flight pattern to get data and update cache periodically.
The Single-Flight pattern is a concurrency design pattern that ensures only one execution of a function is in-flight for a given key at any given time
This can prevent deduplication of requests SDK-side and using JWKs_refresh_interval will ensure that rate limits are not hit.
Thank you for adding your inputs !! The UrlJwkProvider class, is a simple low-level provider that performs a synchronous, blocking network call. It's intentionally kept minimal without any caching or concurrency logic. This design allows it to be a flexible building block. The single-flight pattern and thread management you've described are handled by the GuavaCachedJwkProvider class, which is a decorator that wraps the UrlJwkProvider. This is a common design pattern where a simple provider is decorated with powerful cross-cutting concerns like caching and concurrency. |
tusharpandey13
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Changes
Added a new default method getAll() that allows fetching all available JWKs at once. By default, it throws UnsupportedOperationException unless overridden.
References
Please include relevant links supporting this change such as a:
Testing
Please describe how this can be tested by reviewers. Be specific about anything not tested and reasons why. If this library has unit and/or integration testing, tests should be added for new functionality and existing tests should complete without errors.
Checklist