LIBRESSL-SSL_CTX_SET_SESSION_CACHE_MODE(3)
π NAME π
SSL_CTX_set_session_cache_mode, SSL_CTX_get_session_cache_mode β bestie, this is literally how you turn session caching on and off, okurrr
(also hi, this is from the Library Functions Manual for libssl, and the page name is SSL_CTX_SET_SESSION_CACHE_MODE(3) β iykyk π)
β¨ SYNOPSIS β¨
library βlibsslβ libcrypto #include <openssl/ssl.h>
long
SSL_CTX_set_session_cache_mode(SSL_CTX ctx, long mode);
long
SSL_CTX_get_session_cache_mode(SSL_CTX ctx);
π¦ DESCRIPTION π¦
So SSL_CTX_set_session_cache_mode() is the main character here β it enables or disables session caching by setting the operational mode for ctx to mode. Slay.
And SSL_CTX_get_session_cache_mode() is the chill one: it just returns the cache mode currently in use. No drama, no notes. π
The OpenSSL library can store and retrieve SSL/TLS sessions so they can be reused later, which is honestly iconic of it. The sessions can be held in memory for each ctx β and if more than one SSL_CTX object is being maintained, then the sessions are unique for each SSL_CTX object. Periodt.
So how does reuse actually work π β in order to reuse a session, a client must send the session's id to the server. It can only send exactly one id, no overachieving bestie. The server then either agrees to reuse the session or it starts a full handshake (to create a new session). That's the whole vibe check.
A server will look up the session in its internal session storage. If the session is not found in internal storage, or if lookups for the internal storage have been deactivated (SSL_SESS_CACHE_NO_INTERNAL_LOOKUP), then the server will try the external storage if that's available. Backup plan behavior, we love to see it. π
Since a client may try to reuse a session intended for use in a different context, the session id context must be set by the server (see SSL_CTX_set_session_id_context(3)). Non-negotiable, bestie.
Here are the available session cache modes and modifiers β this is the lineup, and honestly every single one has main character energy:
SSL_SESS_CACHE_OFFβ No session caching for client or server takes place. That's it. Nothing. Crickets. πSSL_SESS_CACHE_CLIENTβ Client sessions are added to the session cache. Ok but here's the thing: there is no reliable way for the OpenSSL library to know whether a session should be reused or which session to choose (because of the abstractBIOlayer, the SSL engine does not have details about the connection), so the application must select the session to be reused by using theSSL_set_session(3)function. Also this option is not activated by default, fyi. πSSL_SESS_CACHE_SERVERβ Server sessions are added to the session cache. When a client proposes a session to be reused, the server looks for the corresponding session in (first) the internal session cache (unlessSSL_SESS_CACHE_NO_INTERNAL_LOOKUPis set), then (second) in the external cache if available. If the session is found, the server will try to reuse the session. And guess what β this is the default. πSSL_SESS_CACHE_BOTHβ Enables bothSSL_SESS_CACHE_CLIENTandSSL_SESS_CACHE_SERVERat the same time. Why choose, honestly. π«ΆSSL_SESS_CACHE_NO_AUTO_CLEARβ Normally the session cache is checked for expired sessions every 255 connections using theSSL_CTX_flush_sessions(3)function. But since this may lead to a delay which cannot be controlled π, the automatic flushing may be disabled andSSL_CTX_flush_sessions(3)can be called explicitly by the application. You're in charge now, bestie.SSL_SESS_CACHE_NO_INTERNAL_LOOKUPβ By setting this flag, session-resume operations in an SSL/TLS server will not automatically look up sessions in the internal cache, even if sessions are automatically stored there. If external session caching callbacks are in use, this flag guarantees that all lookups are directed to the external cache. And since automatic lookup only applies for SSL/TLS servers, the flag has no effect on clients. Clients stay unbothered. β¨SSL_SESS_CACHE_NO_INTERNAL_STOREβ Depending on the presence ofSSL_SESS_CACHE_CLIENTand/orSSL_SESS_CACHE_SERVER, sessions negotiated in an SSL/TLS handshake may be cached for possible reuse. Normally a new session is added to the internal cache as well as any external session caching (callback) that is configured for theSSL_CTX. This flag will prevent sessions being stored in the internal cache (though the application can add them manually usingSSL_CTX_add_session(3)). π
Note: in any SSL/TLS servers where external caching is configured, any successful session lookups in the external cache (e.g., for session-resume requests) would normally be copied into the local cache before processing continues β this flag prevents these additions to the internal cache as well. Important detail, don't skip it!! πΈ
SSL_SESS_CACHE_NO_INTERNALβ Enables bothSSL_SESS_CACHE_NO_INTERNAL_LOOKUPandSSL_SESS_CACHE_NO_INTERNAL_STOREat the same time. Combo deal, ate. π₯
And the default mode is SSL_SESS_CACHE_SERVER. Remember it, it's giving canon. β
π RETURN VALUES π
SSL_CTX_set_session_cache_mode()returns the previously set cache mode. Yes, it remembers the old one, thoughtful queen.SSL_CTX_get_session_cache_mode()returns the currently set cache mode. That's literally its whole job and it does it flawlessly. π
π SEE ALSO π
ssl(3), SSL_CTX_add_session(3), SSL_CTX_ctrl(3), SSL_CTX_flush_sessions(3), SSL_CTX_sess_number(3), SSL_CTX_sess_set_cache_size(3), SSL_CTX_sess_set_get_cb(3), SSL_CTX_set_session_id_context(3), SSL_CTX_set_timeout(3), SSL_session_reused(3), SSL_set_session(3)
Read them, bestie, they're all connected. π§
π HISTORY π
SSL_CTX_set_session_cache_mode() and SSL_CTX_get_session_cache_mode() first appeared in SSLeay 0.6.1 and have been available since OpenBSD 2.4. Vintage but make it cute. β
SSL_SESS_CACHE_NO_INTERNAL_STORE and SSL_SESS_CACHE_NO_INTERNAL were introduced in OpenSSL 0.9.6h. Late arrivals but iconic regardless. π
Debian π June 8, 2025 π SSL_CTX_SET_SESSION_CACHE_MODE(3) β ok that's the whole page bestie, go forth and cache responsibly, mwah π«Άβ¨
π¦ where this page comes from
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2001, 2002 The OpenSSL Project. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms