SSL_CTX_SET_...N_CACHE_MODE(3ossl)
π SSL_CTX_set_session_cache_mode, SSL_CTX_get_session_cache_mode β enable/disable session caching
okay bestie, welcome to the OpenSSL 3ossl manual page that's literally all about whether your sessions get cached or not π this is SSL_CTX_SET_...N_CACHE_MODE and yes the name is a whole mouthful, we're getting through it together, no cap.
β¨ SYNOPSIS β¨
#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);
two functions, both returning long, both taking an SSL_CTX ctx. one sets, one gets. iconique π
πΈ DESCRIPTION πΈ
SSL_CTX_set_session_cache_mode()β turns session caching on or off by setting the operational mode forctxtomode. that's the whole vibe check right there π¦SSL_CTX_get_session_cache_mode()β hands you back whatever cache mode is currently in use. the "what are we even doing right now" function, iykyk.
π NOTES π
So the OpenSSL library can store and retrieve SSL/TLS sessions so they can be reused later, which is lowkey the whole point π₯ The sessions can be held in memory for each ctx, and if you've got more than one SSL_CTX object going at once, the sessions are unique to each SSL_CTX object. no sharing, no crossover, periodt.
For a session to actually get reused, a client has to send the session's id to the server. It can only send exactly one id β one (1) id, bestie, that's the limit π Then the server either agrees to reuse the session or it starts a full handshake to create a new one. either way we move.
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), the server will try the external storage if available.
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)). not optional, don't skip it π«Ά
The following session cache modes and modifiers are available:
π the modes
SSL_SESS_CACHE_OFFβ no session caching for client or server takes place. just... none. zero. the void πSSL_SESS_CACHE_CLIENTβ client sessions are added to the session cache. Here's the thing though: 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 abstract BIO layer, the SSL engine does not have details about the connection), so the application has to select the session to be reused itself using theSSL_set_session(3)function. This option is not activated by default, so it's very much not the main character unless you make it one β¨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. This is the default πSSL_SESS_CACHE_BOTHβ enables bothSSL_SESS_CACHE_CLIENTandSSL_SESS_CACHE_SERVERat the same time. why choose π
π¦ the modifiers
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. 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 take the wheel, 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. As automatic lookup only applies for SSL/TLS servers, the flag has no effect on clients. ngl that last part matters, don't @ me π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 (i.e. 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. sneaky little double duty, honestly π
SSL_SESS_CACHE_NO_INTERNALβ enables bothSSL_SESS_CACHE_NO_INTERNAL_LOOKUPandSSL_SESS_CACHE_NO_INTERNAL_STOREat the same time. combo deal πSSL_SESS_CACHE_UPDATE_TIMEβ updates the timestamp of the session when it is used, increasing the lifespan of the session. The session timeout then applies to last use, rather than creation time. so your session gets a little refresh every time you show up, we love longevity π«Ά
The default mode is SSL_SESS_CACHE_SERVER. β¨
π₯ RETURN VALUES π₯
SSL_CTX_set_session_cache_mode()β returns the previously set cache mode. the "before" picture πΈSSL_CTX_get_session_cache_mode()β returns the currently set cache mode. the "right now" picture π
π§ SEE ALSO π§
ssl(7), SSL_set_session(3), SSL_session_reused(3), SSL_CTX_add_session(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_CTX_flush_sessions(3)
go read them, they're all linkable lore π
π COPYRIGHT π
Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
and that's the whole page bestie, you ate that π mwah π this was OpenSSL 3.5.6, dated 2026-04-07 β screenshot it, cite it, live by it. bye slay πβ
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms