3 releases
new 0.1.2 | Nov 3, 2024 |
---|---|
0.1.1 | Nov 3, 2024 |
0.1.0 | Nov 3, 2024 |
#1013 in Network programming
37 downloads per month
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
~148K SLoC