---
name: "libressl-SSL_CTX_set_session_cache_mode"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-SSL_CTX_set_session_cache_mode"
---

# libressl-SSL\_CTX\_set\_session\_cache\_mode(3)

enable/disable session caching

## NAME

**SSL\_CTX\_set\_session\_cache\_mode**, **SSL\_CTX\_get\_session\_cache\_mode** – enable/disable session caching

## SYNOPSIS

SSL Library (libssl, -lssl) 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

**SSL\_CTX\_set\_session\_cache\_mode**() enables/disables session caching by setting the operational mode for *ctx* to *mode*.

**SSL\_CTX\_get\_session\_cache\_mode**() returns the currently used cache mode.

The OpenSSL library can store/retrieve SSL/TLS sessions for later reuse. The sessions can be held in memory for each *ctx*, if more than one *SSL\_CTX* object is being maintained, the sessions are unique for each *SSL\_CTX* object.

In order to reuse a session, a client must send the session's id to the server. It can only send exactly one id. The server then either agrees to reuse the session or it starts a full handshake (to create a new session).

A server will look up the session in its internal session storage. If the session is not found in internal storage or 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)).

The following session cache modes and modifiers are available:

- SSL\_SESS\_CACHE\_OFF

  No session caching for client or server takes place.

- SSL\_SESS\_CACHE\_CLIENT

  Client sessions are added to the session cache. As there is no reliable way for the OpenSSL library to know whether a session should be reused or which session to choose (due to the abstract BIO layer the SSL engine does not have details about the connection), the application must select the session to be reused by using the SSL\_set\_session(3) function. This option is not activated by default.

- 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 (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 the session. This is the default.

- SSL\_SESS\_CACHE\_BOTH

  Enable both SSL\_SESS\_CACHE\_CLIENT and SSL\_SESS\_CACHE\_SERVER at the same time.

- SSL\_SESS\_CACHE\_NO\_AUTO\_CLEAR

  Normally the session cache is checked for expired sessions every 255 connections using the SSL\_CTX\_flush\_sessions(3) function. Since this may lead to a delay which cannot be controlled, the automatic flushing may be disabled and SSL\_CTX\_flush\_sessions(3) can be called explicitly by the application.

- 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.

- SSL\_SESS\_CACHE\_NO\_INTERNAL\_STORE

  Depending on the presence of SSL\_SESS\_CACHE\_CLIENT and/or SSL\_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 the *SSL\_CTX*. This flag will prevent sessions being stored in the internal cache (though the application can 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 (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.

- SSL\_SESS\_CACHE\_NO\_INTERNAL

  Enable both SSL\_SESS\_CACHE\_NO\_INTERNAL\_LOOKUP and SSL\_SESS\_CACHE\_NO\_INTERNAL\_STORE at the same time.

The default mode is SSL\_SESS\_CACHE\_SERVER.

## RETURN VALUES

**SSL\_CTX\_set\_session\_cache\_mode**() returns the previously set cache mode.

**SSL\_CTX\_get\_session\_cache\_mode**() returns the currently set cache mode.

## SEE ALSO

[ssl(3)](/ssl/3.md), 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)

## 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.

SSL\_SESS\_CACHE\_NO\_INTERNAL\_STORE and SSL\_SESS\_CACHE\_NO\_INTERNAL were introduced in OpenSSL 0.9.6h.
