# JWKS Caching Strategy Recommendations

**URL:** <https://community.auth0.com/t/jwks-caching-strategy-recommendations/183415>\
**Category:** Dev to Dev Hub\
**Tags:** oauth-2-0, protocols\
**Created:** [March 5, 2025, 10:57pm UTC](https://community.auth0.com/t/jwks-caching-strategy-recommendations/183415 "2025-03-05T22:57:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![FrostbyteApps](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/frostbyteapps/32/25731_2.png) [@FrostbyteApps](https://community.auth0.com/u/FrostbyteApps)\
**Post date:** [March 5, 2025, 10:57pm UTC](https://community.auth0.com/t/jwks-caching-strategy-recommendations/183415/1 "2025-03-05T22:57:41Z")

</div>

When looking at the cache control headers for the JWKS endpoints of my project, I receive the following values…

public, max-age=15, stale-while-revalidate=15, stale-if-error=86400

This cache control leads me to believe that I should be re-fetching the jwks every 15 seconds in order to obey the caching behavior sent back from the endpoint.

However, fetching every 15 seconds seems excessive. Other posts on the forum recommends hours between fetching.

Why don’t the cache control headers contain data that aligns with the recommendations form support here?

---

<div class="post-metadata">

**Author:** ![vlad.murarasu](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/vlad.murarasu/32/72793_2.png) [@vlad.murarasu](https://community.auth0.com/u/vlad.murarasu)\
**Post date:** [March 19, 2025, 6:33pm UTC](https://community.auth0.com/t/jwks-caching-strategy-recommendations/183415/4 "2025-03-19T18:33:25Z")

</div>

Hi @FrostbyteApps,

There isn’t an exact number of seconds you need to cache the JWKs, as stated in this post:

> [@Feedback on Caching JWKS for JWT Verification in Ruby](https://community.auth0.com/t/feedback-on-caching-jwks-for-jwt-verification-in-ruby/138885/3):
>
> Hey @raphael.egeley welcome to the community! Great Idea! Overall, I think your approach is good - There isn’t a recommended time to cache tokens. The following post expands on caching JWKs and is still useful despite being a few years old.

JWKs will return the same set of keys most of the time, so you can just cache them and keep using them and if they get denied you can request them again.

If you have any other question feel free to reach out.

Have a good one,  
Vlad

---

<div class="post-metadata">

**Author:** ![FrostbyteApps](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/frostbyteapps/32/25731_2.png) [@FrostbyteApps](https://community.auth0.com/u/FrostbyteApps)\
**Post date:** [March 26, 2025, 2:39pm UTC](https://community.auth0.com/t/jwks-caching-strategy-recommendations/183415/5 "2025-03-26T14:39:06Z")

</div>

Hey Vlad, thanks for the context. Can you elaborate on what you mean by denied? Are you suggesting that any time I attempt to authorize a token using the public keys, and they fail, I should attempt to re-fetch the public keys and try again?

---

<div class="post-metadata">

**Author:** ![vlad.murarasu](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/vlad.murarasu/32/72793_2.png) [@vlad.murarasu](https://community.auth0.com/u/vlad.murarasu)\
**Post date:** [March 26, 2025, 3:41pm UTC](https://community.auth0.com/t/jwks-caching-strategy-recommendations/183415/6 "2025-03-26T15:41:44Z")

</div>

Yes you should refetch the public keys and try again. The signing keys can be found in your tenants settings. They need to be refetched only if they get revoked.

Have a good one,  
Vlad

---

<div class="post-metadata">

**Author:** ![FrostbyteApps](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/frostbyteapps/32/25731_2.png) [@FrostbyteApps](https://community.auth0.com/u/FrostbyteApps)\
**Post date:** [March 26, 2025, 5:26pm UTC](https://community.auth0.com/t/jwks-caching-strategy-recommendations/183415/7 "2025-03-26T17:26:03Z")

</div>

Is there a way to distinguish that the verification failed b/c the keys were incorrect vs the authorization token was invalid?

---

<div class="post-metadata">

**Author:** ![vlad.murarasu](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/vlad.murarasu/32/72793_2.png) [@vlad.murarasu](https://community.auth0.com/u/vlad.murarasu)\
**Post date:** [March 27, 2025, 3:46pm UTC](https://community.auth0.com/t/jwks-caching-strategy-recommendations/183415/8 "2025-03-27T15:46:53Z")

</div>

Yes, you will receive different error messages based on the reason.

For authorization token It might be something like:

`UnauthorizedError: No authorization token was found`  
or  
`UnauthorizedError: Authorization token in invalid`

For the JWKS it’s `JsonWebTokenError`, `JsonWebKeySetsError` or `jwks Failure: Error:` followed by the reason. It can either be `Invalid certificate` or `Invalid signing key`.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [April 10, 2025, 3:47pm UTC](https://community.auth0.com/t/jwks-caching-strategy-recommendations/183415/9 "2025-04-10T15:47:42Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.

---

<div class="post-metadata">

**Author:** ![remus.ivan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/remus.ivan/32/68771_2.png) [@remus.ivan](https://community.auth0.com/u/remus.ivan)\
**Post date:** [September 5, 2025, 8:38pm UTC](https://community.auth0.com/t/jwks-caching-strategy-recommendations/183415/10 "2025-09-05T20:38:01Z")

</div>


