# Keeping users logged in with Keycloak 25

DevFeed: [Keeping users logged in with Keycloak 25](<https://devfeed.tech/articles/keeping-users-logged-in-with-keycloak-25-31648.md>)

Original publisher: [Read original article](<https://www.keycloak.org/2024/06/persistent-user-sessions-in-preview>)

Author: Alexander Schwartz

Published: 2024-06-12T00:00:00Z

Content type: article

Language: en

Sources: [Keycloak Blog](<https://devfeed.tech/sources/keycloak-blog.md>)

Topics: [Keycloak](<https://devfeed.tech/topics/keycloak.md>), [Database](<https://devfeed.tech/topics/database.md>), [Cache](<https://devfeed.tech/topics/cache.md>), [configuration](<https://devfeed.tech/topics/configuration.md>)

Tags: [cache](<https://devfeed.tech/tags/cache.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [database](<https://devfeed.tech/tags/database.md>), [github](<https://devfeed.tech/tags/github.md>), [idm](<https://devfeed.tech/tags/idm.md>), [kerberos](<https://devfeed.tech/tags/kerberos.md>), [keycloak](<https://devfeed.tech/tags/keycloak.md>), [ldap](<https://devfeed.tech/tags/ldap.md>), [openid-connect](<https://devfeed.tech/tags/openid-connect.md>), [saml](<https://devfeed.tech/tags/saml.md>), [sso](<https://devfeed.tech/tags/sso.md>)

## AI overview

Keycloak 25 introduces persistent user sessions as a preview feature. When enabled, sessions are stored in the database and can be restored from it when absent from memory, allowing users to continue without re-authentication. The feature may reduce memory usage but increase database activity, CPU and IOPS utilization, and latency.

## Source excerpt

Previous versions of Keycloak would store regular user sessions (also called online user sessions) only in memory. Due to that, all users would be logged out when you shut down or restart the Keycloak cluster. With Keycloak 25, there is a preview feature "persistent user sessions", which stores the user sessions in its database. If a session is not found in memory, it is loaded from the database, and the user can continue to use their session without the need to re-authenticate. The preview feature is disabled by default, and you need to enable it with the persistent-user-sessions feature flag to try it out. You can help to make this feature fully supported by providing feedback in this GitHub discussion thread. For June 24th, we are planning an ask-me-anything session for persistent sessions. Changed runtime behavior of Keycloak and the Database With this feature enabled, Keycloak's memory usage might be reduced and the database usage may increase. Keycloak will default to a maximum of 10'000 entries for each of the caches sessions, clientSessions, offlineSessions, and offlineClientSessions if no other maximum size is configured in Keycloak's cache configuration XML file. If you want to keep more sessions in memory, see Configuring distributed caches on how to configure a different size. The options spi-user-sessions-infinispan-offline-session-cache-entry-lifespan-override and spi-user-sessions-infinispan-offline-client-session-cache-entry-lifespan-override are ignored, as instead the maximum entry size is used. External Infinispan instances are supported for multi-site setups of Keycloak. If you use such a setup and have enabled persistent user sessions, you can (and should) set a maximum number of sessions to be kept in the external Infinispan to limit the memory consumption of the external Infinispan. See Infinispan's docs on how to configure eviction in the Infinispan caches. If the number of concurrent user sessions exceeds the maximum cache size in Keycloak,