pub struct SessionCache { /* private fields */ }Expand description
Thread-safe in-memory TLS session cache
Stores session tickets for TLS 1.3 resumption. This enables clients to reconnect without performing full handshakes, reducing latency by 50-70%.
Pass the same cache (in an Arc) to every
TlsClient::connect_with_session
call: the TLS layer stores the server’s session tickets in it and offers them on
the next connection to the same server name. Those TLS tickets are kept in a
rustls session store bounded by max_entries and expire as the server’s ticket
lifetime says; default_ttl applies to entries added with store.
rustls only resumes a session with the same certificate verifier that checked
the original connection, so the cache also keeps the TLS client configuration
built for each distinct TlsClientConfig and reuses it. Certificate, key and CA
files are therefore read on the first connection with a given configuration; call
clear after replacing those files.
Implementations§
Source§impl SessionCache
impl SessionCache
Sourcepub async fn store<S: Into<String>>(&self, session_id: S, ticket: Vec<u8>)
pub async fn store<S: Into<String>>(&self, session_id: S, ticket: Vec<u8>)
Store a session ticket in the cache
This is typically called by the TLS layer after establishing a connection. Automatically manages eviction when cache is full.
§Arguments
session_id- Unique session identifierticket- Serialized TLS session ticket
Sourcepub async fn stats(&self) -> SessionCacheStats
pub async fn stats(&self) -> SessionCacheStats
Get current cache statistics