SSL_CTX_SESS_SET_CACHE_SIZE(3ossl)
π SSL_CTX_SESS_SET_CACHE_SIZE(3ossl) β the OpenSSL session-cache-size glow-up π
okay bestie, welcome to the OpenSSL corner of the manual, where we talk about how many TLS sessions your context is allowed to keep sitting in its little internal cache. it's giving β¨housekeepingβ¨ and honestly? iconic.
πΈ NAME πΈ
SSL_CTX_sess_set_cache_size, SSL_CTX_sess_get_cache_size β manipulate session cache size π«Ά
β¨ SYNOPSIS β¨
#include <openssl/ssl.h>
long SSL_CTX_sess_set_cache_size(SSL_CTX *ctx, long t);
long SSL_CTX_sess_get_cache_size(SSL_CTX *ctx);
π DESCRIPTION π
okay so, two functions, both tiny, both main-character.
SSL_CTX_sess_set_cache_size()β sets the size of the internal session cache of contextctxtot. heads up though: this value is a hint, not an absolute, okay? it's not a hard promise. the notes below spill the tea on why. πSSL_CTX_sess_get_cache_size()β returns the currently valid session cache size. that's it. that's the whole job. she's simple and she ate. π
π¦ NOTES π¦
so the internal session cache size defaults to SSL_SESSION_CACHE_MAX_SIZE_DEFAULT, which is currently 1024*20, which means up to 20000 sessions can be held at once. literally twenty thousand little sessions vibing in there. π
you can change that with the SSL_CTX_sess_set_cache_size() call. and there's a special case bestie: the size 0, which is used for unlimited size. zero means infinity, which is so chaotic of it and honestly? we respect it. π
if adding a session makes the cache exceed its size, then unused sessions get dropped from the end of the cache. bye bestie π. cache space may also be reclaimed by calling SSL_CTX_flush_sessions(3) to remove expired sessions.
and here's the lowkey important bit: if you reduce the size of the session cache and there are already more sessions in the cache than the new size allows, old sessions will be removed at the next time a session shall be added. this removal is NOT synchronized with the expiration of sessions. so yeah, no clock sync, no scheduled cleanup β it just happens whenever the next add comes through. no cap.
β οΈ reminder: the size is a hint, not an absolute. don't come for me when the cache doesn't obey you to the exact session.
π RETURN VALUES π
SSL_CTX_sess_set_cache_size()β returns the previously valid size. like, the size from before you changed it. the before pic. πΈSSL_CTX_sess_get_cache_size()β returns the currently valid size. the now pic. β¨
π SEE ALSO π
go read those too, bestie, iykyk π
π COPYRIGHT π
Copyright 2001-2016 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, periodt. π this was OpenSSL version 3.5.9, dated 2026-09-29 β thanks for coming to my TED talk, love u, bye π§πΈ
π¦ 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