pub struct SessionMap { /* private fields */ }Expand description
Thread-safe map of session keys (typically domains) to proxy bindings.
All operations acquire short-lived locks to minimise contention.
§Example
use stygian_proxy::session::SessionMap;
use std::time::Duration;
use uuid::Uuid;
let map = SessionMap::new();
let id = Uuid::new_v4();
map.bind("example.com", id, Duration::from_secs(60));
assert_eq!(map.lookup("example.com"), Some(id));Implementations§
Source§impl SessionMap
impl SessionMap
Sourcepub fn lookup(&self, key: &str) -> Option<Uuid>
pub fn lookup(&self, key: &str) -> Option<Uuid>
Look up the proxy bound to key, returning None when no session
exists or the existing session has expired.
Expired entries are lazily removed on the next bind
or purge_expired call.
Sourcepub fn bind(&self, key: &str, proxy_id: Uuid, ttl: Duration)
pub fn bind(&self, key: &str, proxy_id: Uuid, ttl: Duration)
Bind key to proxy_id with the given TTL. Overwrites any existing
session for the same key.
Sourcepub fn purge_expired(&self) -> usize
pub fn purge_expired(&self) -> usize
Remove all expired sessions, returning the number removed.
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Returns the number of active (non-expired) sessions.
Trait Implementations§
Source§impl Clone for SessionMap
impl Clone for SessionMap
Source§fn clone(&self) -> SessionMap
fn clone(&self) -> SessionMap
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SessionMap
impl Debug for SessionMap
Auto Trait Implementations§
impl Freeze for SessionMap
impl !RefUnwindSafe for SessionMap
impl Send for SessionMap
impl Sync for SessionMap
impl Unpin for SessionMap
impl UnsafeUnpin for SessionMap
impl !UnwindSafe for SessionMap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more