Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/usage/frameworks/litestar.rst
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,30 @@ Register a :class:`SQLAlchemyStore` under the session store name and let Litesta

The registered store name must match ``ServerSideSessionConfig.store``, which is ``"sessions"`` unless you override it.

.. note::

**Cleaning up expired sessions.** Unlike the backend-based integration,
:class:`SQLAlchemyStore <advanced_alchemy.extensions.litestar.store.SQLAlchemyStore>`
does not expose a ``delete_expired()`` method. Expiry is applied lazily: expired
entries stop being returned by ``get()``, but their rows are **not** removed from
the table, so it grows over time. Until a dedicated method is available (see
`issue #787 <https://github.com/litestar-org/advanced-alchemy/issues/787>`_),
schedule a periodic cleanup against the store's model table, for example:

.. code-block:: python

from sqlalchemy import delete, func

async def cleanup_expired_sessions() -> None:
async with alchemy_config.get_session() as db_session:
await db_session.execute(
delete(SessionStore).where(SessionStore.expires_at <= func.now())
)
await db_session.commit()

Run it from an ``on_startup`` hook, a scheduler such as SAQ, or an external cron
job. Do not use ``delete_all()`` for this — it removes live sessions too.
Comment thread
hasansezertasan marked this conversation as resolved.
Outdated

Backend-Based Integration
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
Loading