---
name: "libressl-SSL_CTX_add_session"
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_add_session"
---

# libressl-SSL\_CTX\_add\_session(3)

manipulate session cache

## NAME

**SSL\_CTX\_add\_session**, **SSL\_CTX\_remove\_session** – manipulate session cache

## SYNOPSIS

SSL Library (libssl, -lssl) libcrypto

**#include \<openssl/ssl.h\>**

*int*\

**SSL\_CTX\_add\_session**(*SSL\_CTX \*ctx*, *SSL\_SESSION \*c*);

*int*\

**SSL\_CTX\_remove\_session**(*SSL\_CTX \*ctx*, *SSL\_SESSION \*c*);

## DESCRIPTION

**SSL\_CTX\_add\_session**() adds the session *c* to the context *ctx*. The reference count for session *c* is incremented by 1. If a session with the same session id already exists, the old session is removed by calling SSL\_SESSION\_free(3).

**SSL\_CTX\_remove\_session**() removes the session *c* from the context *ctx* and marks it as non-resumable. SSL\_SESSION\_free(3) is called once for *c*.

When adding a new session to the internal session cache, it is examined whether a session with the same session id already exists. In this case it is assumed that both sessions are identical. If the same session is stored in a different *SSL\_SESSION* object, the old session is removed and replaced by the new session. If the session is actually identical (the *SSL\_SESSION* object is identical), **SSL\_CTX\_add\_session**() is a no-op, and the return value is 0.

If a server *SSL\_CTX* is configured with the SSL\_SESS\_CACHE\_NO\_INTERNAL\_STORE flag then the internal cache will not be populated automatically by new sessions negotiated by the SSL/TLS implementation, even though the internal cache will be searched automatically for session-resume requests (the latter can be suppressed by SSL\_SESS\_CACHE\_NO\_INTERNAL\_LOOKUP). So the application can use **SSL\_CTX\_add\_session**() directly to have full control over the sessions that can be resumed if desired.

## RETURN VALUES

The following values are returned by all functions:

- 0

  The operation failed. In case of the add operation, it was tried to add the same (identical) session twice. In case of the remove operation, the session was not found in the cache.

- 1

  The operation succeeded.

## SEE ALSO

[ssl(3)](/ssl/3.md), SSL\_CTX\_set\_session\_cache\_mode(3), SSL\_SESSION\_free(3)

## HISTORY

**SSL\_CTX\_add\_session**() and **SSL\_CTX\_remove\_session**() first appeared in SSLeay 0.8.0 and have been available since OpenBSD 2.4.
