How to setup keycloak to daily clear expired sessions from cache

Hi
Can anyone tell me where and how to configure keycloak to periodically clear expired sessions from the in-memory cache?

With our current setup, all the sessions including the expired, remain in memory forever until keycloak is restarted.

We use a single Keycloak 15.0.2 instance running in a docker container.

I’m happy to provide any information you require :slight_smile:
Many thanks for considering my request.

Hi, @Flurin, did you resolve this issue?

It could be related to: Expired cache objects in infinispan cache are never garbage collected in standalone configuration · Issue #10461 · keycloak/keycloak · GitHub.

Try adding this to the config or upgrade to Keycloak version 16.1.1 or later:

<expiration lifespan="900000000000000000"/>

In our case even with this settings enabled we sometimes see OutOfMemory: Java heap space issues. We are using distributed-cache between multiple nodes of Keycloak. So most probably xmx settings also needs to be updated in case you have high load.

Hi @dionis

Thanks for your reply. Meanwhile, we upgraded to Keycloak 18 and the issue seems resolved