pub struct DtlsSessionCache { /* private fields */ }Expand description
A bounded, TTL-expiring cache of DTLS sessions keyed by peer address.
Constrained devices perform expensive handshakes (especially with post-quantum key exchange), so session resumption significantly reduces latency and power consumption for repeated EST operations.
§Capacity Management
The cache enforces a maximum number of sessions. When full, expired sessions are purged first. If still full, the oldest session is evicted.
Implementations§
Source§impl DtlsSessionCache
impl DtlsSessionCache
Sourcepub fn new(max_sessions: usize, ttl: Duration) -> Self
pub fn new(max_sessions: usize, ttl: Duration) -> Self
Creates a new session cache.
§Arguments
max_sessions- Maximum number of sessions to cache.ttl- Duration after which sessions expire and become eligible for eviction.
Sourcepub fn insert(&mut self, session: DtlsSession)
pub fn insert(&mut self, session: DtlsSession)
Inserts a session into the cache.
If the cache is at capacity, expired sessions are purged first. If still full, the oldest session is evicted to make room.
Sourcepub fn get(&mut self, peer_addr: &SocketAddr) -> Option<&DtlsSession>
pub fn get(&mut self, peer_addr: &SocketAddr) -> Option<&DtlsSession>
Retrieves a cached session for the given peer address.
Returns None if no session exists or if the session has expired.
Expired sessions are removed on access.
Sourcepub fn remove(&mut self, peer_addr: &SocketAddr) -> Option<DtlsSession>
pub fn remove(&mut self, peer_addr: &SocketAddr) -> Option<DtlsSession>
Removes a session from the cache.
Returns the removed session, or None if no session existed for
the given address.
Sourcepub fn cleanup_expired(&mut self) -> usize
pub fn cleanup_expired(&mut self) -> usize
Removes all expired sessions from the cache.
Returns the number of sessions removed.
Sourcepub fn max_sessions(&self) -> usize
pub fn max_sessions(&self) -> usize
Returns the configured maximum number of sessions.