greentic_session/
store.rs

1use crate::model::{Cas, Session, SessionKey};
2use greentic_types::GResult;
3
4pub trait SessionStore: Send + Sync + 'static {
5    /// Fetch by key; returns `(Session, Cas)` if present.
6    fn get(&self, key: &SessionKey) -> GResult<Option<(Session, Cas)>>;
7
8    /// Create or replace, returning the new `Cas`.
9    fn put(&self, session: Session) -> GResult<Cas>;
10
11    /// Update using CAS—only writes if `expected` matches the stored Cas.
12    fn update_cas(&self, session: Session, expected: Cas) -> GResult<Result<Cas, Cas>>;
13
14    /// Delete by key; return true if something was deleted.
15    fn delete(&self, key: &SessionKey) -> GResult<bool>;
16
17    /// Refresh TTL or `updated_at` without modifying payload.
18    fn touch(&self, key: &SessionKey, ttl_secs: Option<u32>) -> GResult<bool>;
19}