SSL_CTX_SET_...N_CACHE_MODE(3ossl)
๐ SSL_CTX_SET_...N_CACHE_MODE ๐
okay bestie, so this one is from the OpenSSL manual, section 3ossl โ it's the girlies that handle session caching on your SSL_CTX. Come sit, we're doing this together. ๐ซถ
โจ NAME โจ
SSL_CTX_set_session_cache_mode, SSL_CTX_get_session_cache_mode โ turn session caching on or off like a little light switch ๐
๐ธ 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);
๐ฆ DESCRIPTION ๐ฆ
SSL_CTX_set_session_cache_mode() โ this one enables or disables session caching, by setting the operational mode for ctx to <mode>. That's it, that's the whole job, no cap. ๐
SSL_CTX_get_session_cache_mode() โ this one just tells you which cache mode you're currently on. It's giving "hey what mode are we in bestie". โจ
๐ NOTES ๐
okay so the OpenSSL library can store and retrieve SSL/TLS sessions so you can reuse them later. Like saving your game so you don't gotta replay the whole thing. ๐ฎ
The sessions can live in memory, per ctx โ and lowkey important: if you're maintaining more than one SSL_CTX object, the sessions are unique for each SSL_CTX object. No sharing, no crossover, they each have their own lil world. ๐
So for a session to actually get reused, the client has to send the session's id to the server. It can send exactly one id โ not two, not zero, one. Then the server either agrees to reuse the session, or it starts a full handshake to create a brand new session. Iconic either way honestly. ๐
A server will look up the session in its internal session storage. And if the session isn't found there, 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 available. Backup plan energy. ๐
โ ๏ธ Now this part is important: since a client may try to reuse a session that was 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). Do not skip this one bestie, I'm begging. ๐ญ
Here are the session cache modes and modifiers that are available:
SSL_SESS_CACHE_OFFโ no session caching for client or server takes place. Nothing. Nada. The cache is asleep. ๐คSSL_SESS_CACHE_CLIENTโ client sessions get added to the session cache. But here's the tea: there's 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 doesn't have details about the connection. So the application has to pick the session to be reused itself, using theSSL_set_session(3)function. This option is not activated by default. ๐SSL_SESS_CACHE_SERVERโ server sessions get 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 it. This is the default. โจSSL_SESS_CACHE_BOTHโ enables bothSSL_SESS_CACHE_CLIENTandSSL_SESS_CACHE_SERVERat the same time. Both. At once. Greedy, we love her. ๐SSL_SESS_CACHE_NO_AUTO_CLEARโ normally the session cache gets checked for expired sessions every 255 connections, using theSSL_CTX_flush_sessions(3)function. But since that may lead to a delay which cannot be controlled, the automatic flushing can be disabled โ and thenSSL_CTX_flush_sessions(3)can be called explicitly by the application. You're driving now. ๐SSL_SESS_CACHE_NO_INTERNAL_LOOKUPโ set this flag and 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, this flag has no effect on clients. ๐งSSL_SESS_CACHE_NO_INTERNAL_STOREโ depending on whetherSSL_SESS_CACHE_CLIENTand/orSSL_SESS_CACHE_SERVERare present, sessions negotiated in an SSL/TLS handshake may be cached for possible reuse. Normally a new session gets added to the internal cache as well as any external session caching (callback) that's configured for theSSL_CTX. This flag will prevent sessions from being stored in the internal cache โ though the application can still 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. ๐
SSL_SESS_CACHE_NO_INTERNALโ enables bothSSL_SESS_CACHE_NO_INTERNAL_LOOKUPandSSL_SESS_CACHE_NO_INTERNAL_STOREat the same time. Combo move. ๐ฅSSL_SESS_CACHE_UPDATE_TIMEโ updates the timestamp of the session when it's used, which increases the lifespan of the session. The session timeout applies to last use, rather than creation time. Glow-up for your sessions, honestly. โญ
And the default mode is SSL_SESS_CACHE_SERVER. Remember that. ๐
๐ RETURN VALUES ๐
SSL_CTX_set_session_cache_mode() returns the previously set cache mode. (Yes, the old one. She remembers the before-times.)
SSL_CTX_get_session_cache_mode() returns the currently set cache mode.
๐ 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)
๐ COPYRIGHT ๐
Copyright 2001-2026 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 ๐ซถ this was OpenSSL version 3.5.9, dated 2026-09-29 โ go forth and cache those sessions responsibly, mwah ๐ โจ
๐ฆ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 ยท Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 ยท Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 ยท Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 ยท Apache-2.0
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms