Skip to content

fix: cache remote JWK Set instances to reduce redundant JWKS requests#43

Merged
xiaoyijun merged 1 commit into
masterfrom
xiaoyijun-fix-jwks-cache
Jan 20, 2026
Merged

fix: cache remote JWK Set instances to reduce redundant JWKS requests#43
xiaoyijun merged 1 commit into
masterfrom
xiaoyijun-fix-jwks-cache

Conversation

@xiaoyijun
Copy link
Copy Markdown
Contributor

Summary

Previously, TokenVerifier.createVerifyJwtFunction created a new createRemoteJWKSet instance on every token verification call. This caused jose's internal caching mechanisms (cooldownDuration, cacheMaxAge) to be ineffective, resulting in redundant HTTP requests to the JWKS endpoint.

This PR caches the remote JWK Set instances by JWKS URI, allowing jose's built-in caching to work as intended:

  • 30-second cooldown between requests
  • 10-minute cache max age
  • Automatic key rotation handling when no matching key is found

Closes #42

Testing

unit tests

Checklist

  • .changeset
  • unit tests
  • integration tests
  • necessary TSDoc comments

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@xiaoyijun xiaoyijun self-assigned this Jan 19, 2026
@xiaoyijun xiaoyijun merged commit e4b2bb2 into master Jan 20, 2026
5 checks passed
@xiaoyijun xiaoyijun deleted the xiaoyijun-fix-jwks-cache branch January 20, 2026 03:21
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.

jwks endpoint called too often

2 participants