Standard library / crypto/tls
tls.ClientSessionCache
Interface for client-side session state storage. Get retrieves by cache key; Put updates or is documented to remove on nil. Implementations must support concurrent calls. Go 1.23.2 LRU cache may return (nil, true) after Put(nil) for an absent key; check both the state and ok. The example uses a synthetic non-resumable state only to show existing-entry removal. Expected stdout: 'false\n'.
Formal Syntax & Structure
go syntaxgo
type ClientSessionCache interface { Get(sessionKey string) (session *ClientSessionState, ok bool)
Put(sessionKey string, cs *ClientSessionState)}Working Example
Example Snippetgo
package main
import ( "crypto/tls" "fmt")
func main() { var cache tls.ClientSessionCache = tls.NewLRUClientSessionCache(2) cache.Put("demo", &tls.ClientSessionState{}) cache.Put("demo", nil) _, ok := cache.Get("demo") fmt.Println(ok)}
func must[T any](v T, e error) T { if e != nil { panic(e) } return v}func check(e error) { if e != nil { panic(e) }}