# UserStorageProvider SPI keycloak user cache not used or invalidated

**URL:** <https://forum.keycloak.org/t/userstorageprovider-spi-keycloak-user-cache-not-used-or-invalidated/29301>\
**Category:** Getting advice\
**Created:** [December 19, 2024, 9:04pm UTC](https://forum.keycloak.org/t/userstorageprovider-spi-keycloak-user-cache-not-used-or-invalidated/29301 "2024-12-19T21:04:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonnewell](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@jonnewell](https://forum.keycloak.org/u/jonnewell)\
**Post date:** [December 19, 2024, 9:04pm UTC](https://forum.keycloak.org/t/userstorageprovider-spi-keycloak-user-cache-not-used-or-invalidated/29301/1 "2024-12-19T21:04:02Z")

</div>

Hello, I’m having some trouble with my UserStorageProvider and built-in keycloak caching. I can see the user being placed into cache . I can see the cached user being utilized in the `IsValid()` method during login. The user cache is not used on the second instantiation of the UserStorageProvider SPI when tokens are being created. I am assuming that the it is invalidated, but I can’t tell where/why. Another user, [pauloj] mentioned a solution when using a custom authenticator but I’m using the built in authenticator.

---

<div class="post-metadata">

**Author:** ![pauloj](https://avatars.discourse-cdn.com/v4/letter/p/858c86/32.png) [@pauloj](https://forum.keycloak.org/u/pauloj)\
**Post date:** [December 21, 2024, 1:05pm UTC](https://forum.keycloak.org/t/userstorageprovider-spi-keycloak-user-cache-not-used-or-invalidated/29301/2 "2024-12-21T13:05:44Z")

</div>

What ultimately lead me to finding what I did was printing stack traces where my SPIs getUserById was being called, so that I could see the calling chain. This let me find the role invalidation issue, and the other aspects of the user that were needed by my auth from in the TOKEN phase.

Additionally, I had upped the log level of the infinispan cache classes.

I hope these same things may help you see WHEN/IF your user is getting marked for invalidation and determine why
