#tower-sessions #session #tower #axum #cookies

tower-sessions-file-store

Store sessions for Tower Session store on the file system

3 releases

0.1.2 Nov 3, 2024
0.1.1 Nov 3, 2024
0.1.0 Nov 3, 2024

#1096 in Network programming

Download history 182/week @ 2024-10-28 138/week @ 2024-11-04 10/week @ 2024-11-11

330 downloads per month

MIT license

9KB
127 lines

Usage

let session_store = FileSessionStorage::new();
let session_layer = SessionManagerLayer::new(session_store)
    .with_expiry(Expiry::OnInactivity(Duration::secs(60 * 60)));
let deletion_task = tokio::task::spawn(
    session_store
        .clone()
        .continuously_delete_expired(tokio::time::Duration::from_secs(60 * 60)),
);

app.layer(session_layer);

Issues or pull requests welcome.


lib.rs:

Overview

A session storage that stores each session in a seperate file in a special folder (default ".sessions")

Useful when you want something more persistant than a in memory store but don't want to setup an entire database, especially during local development. Should work fine in production environments though.

Expiry

You can enable automatically deleting expired sessions like this:

let deletion_task = tokio::task::spawn(
    session_store
    .clone()
    .continuously_delete_expired(tokio::time::Duration::from_secs(60)),
);

By default, it will only load sessions to check their expirty if the last modified date of the file is at least 60 seconds. You can adjust this with set_minimum_expiry_date. Ideally the expiry date would be the same as the duration of your sessions.

Dependencies

~6–13MB
~146K SLoC