Need to empty User Cache after calling user.leaveGroup()

We are customizing Keycloak and we use the Java function user.leaveGroup().

The user is removed from the group as a member (click on group and then members) but the group still shows up in the user´s groups (click on user and then groups). So, the two views does not show the same.

After clearing the user cache, the group is also removed under the user´s group tab.

Is there a better posibility than clearing the cache?

we are still trying to find a solution.

@janine Make shure you are getting the userManager instance from keycloakSession.users(). The keycloakSession.users() resolves a UserCache.class (or something like that) witch is an instance of UserCacheSession.

Long story short, if you perform any user operation from the UserCacheSession witch implemens same interface as UserManager, keycloak’s will handler the cache cleanup for you.

You can also inject the UserCache.class directilly keycloakSession.getProvider(UserCache.class)… but it will be simplier to use keycloakSession.users();