Skip to main content

Module session_cache

Module session_cache 

Source
Expand description

§TLS Session Cache

This module provides in-memory TLS session ticket caching for session resumption. Session resumption reduces the handshake overhead by ~50-70%, allowing clients to reconnect without full TLS 1.3 handshakes.

§Features

  • Thread-safe: Uses Arc<Mutex<>> for safe concurrent access
  • TTL-based expiration: Sessions expire after configurable duration
  • Memory-bounded: Configurable maximum entries to prevent unbounded growth
  • Non-blocking lookups: Fast session retrieval without blocking other operations

§Performance

  • Lookup: ~100-200ns (HashMap)
  • Insertion: ~500-1000ns (with lock contention)
  • Eviction: O(n) for expired entries, but typically O(1) for normal lookups

§Usage

use network_protocol::transport::session_cache::SessionCache;
use std::time::Duration;

// Create a cache with 1000 max entries and 1-hour TTL
let cache = SessionCache::new(1000, Duration::from_secs(3600));

// Store a session (typically handled internally by TLS layer)
cache.store(session_id.clone(), ticket.clone()).await;

// Retrieve for resumption (returned as Arc<Vec<u8>>)
if let Some(ticket) = cache.get(&session_id).await {
    // Use ticket for session resumption
}

Structs§

SessionCache
Thread-safe in-memory TLS session cache
SessionCacheStats
Statistics about the session cache