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 abstract BIO layer, the SSL engine doesn't have details about the connection. So the application has to pick the session to be reused itself, using the SSL_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 โ€” unless SSL_SESS_CACHE_NO_INTERNAL_LOOKUP is 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 both SSL_SESS_CACHE_CLIENT and SSL_SESS_CACHE_SERVER at 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 the SSL_CTX_flush_sessions(3) function. But since that may lead to a delay which cannot be controlled, the automatic flushing can be disabled โ€” and then SSL_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 whether SSL_SESS_CACHE_CLIENT and/or SSL_SESS_CACHE_SERVER are 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 the SSL_CTX. This flag will prevent sessions from being stored in the internal cache โ€” though the application can still add them manually using SSL_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 both SSL_SESS_CACHE_NO_INTERNAL_LOOKUP and SSL_SESS_CACHE_NO_INTERNAL_STORE at 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 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