Search documentation of ssl

# View Source ssl_session_cache_api behaviour (ssl v11.2.1)

TLS session cache API

Defines the API for the TLS session cache (pre TLS-1.3) so that the data storage scheme can be replaced by defining a new callback module implementing this API.

# Summary

## Types

partial_key()

The opaque part of the key. Does not need to be handled by the callback.

session()

The session data that is stored for each session.

session_cache_key()

A key to an entry in the session cache.

session_cache_ref()

A term that can be used to reference the cache.

## Callbacks

delete(CacheRef, Key)

Deletes a cache entry.

foldl(Fun, Acc0, CacheRef)

Calls `Fun(Elem, AccIn)` on successive elements of the cache, starting with `AccIn == Acc0`.

init(InitArgs)

Performs possible initializations of the cache and returns a reference to it that is used as parameter to the other API functions.

lookup(CacheRef, Key)

Looks up a cache entry. Is to be callable from any process.

select_session(CacheRef, Server)

Selects sessions that can be reused, that is sessions that include `PartialKey` in its key. Is to be callable from any process.

size(CacheRef)

Returns the number of sessions in the cache.

terminate(CacheRef)

Takes care of possible cleanup that is needed when the cache handling process terminates.

update(CacheRef, Key, Session)

Caches a new session or updates an already cached one.

# Types

Link to this opaque

# partial_key()

View Source (since OTP R14B)

    -opaque partial_key()

The opaque part of the key. Does not need to be handled by the callback.

Link to this opaque

# session()

View Source (since OTP R14B)

    -opaque session()

The session data that is stored for each session.

Link to this type

# session_cache_key()

View Source (since OTP R14B)

    -type session_cache_key() :: {partial_key(), ssl:session_id()}.

A key to an entry in the session cache.

Link to this type

# session_cache_ref()

View Source (since OTP R14B)

    -type session_cache_ref() :: any().

A term that can be used to reference the cache.

# Callbacks

Link to this callback

# delete(CacheRef, Key)

View Source (since OTP R14B)

    -callback delete(CacheRef, Key) -> DoNotCare
                        when CacheRef :: session_cache_ref(), Key :: session_cache_key(), DoNotCare :: any().

Deletes a cache entry.

Is only called from the cache handling process.

Link to this callback

# foldl(Fun, Acc0, CacheRef)

View Source (optional) (since OTP R14B)

    -callback foldl(Fun, Acc0, CacheRef) -> Acc
                       when Fun :: fun(), Acc0 :: term(), CacheRef :: session_cache_ref(), Acc :: term().

Calls `Fun(Elem, AccIn)` on successive elements of the cache, starting with `AccIn == Acc0`.

`Fun/2` must return a new accumulator, which is passed to the next call. The function returns the final value of the accumulator. `Acc0` is returned if the cache is empty.

> #### Note

> Since OTP-23.3 this functions is only used on the client side and does not need to implemented for a server cache.

Link to this callback

# init(InitArgs)

View Source (since OTP 18.0)

    -callback init(InitArgs) -> CacheRef when InitArgs :: list(), CacheRef :: session_cache_ref().

Performs possible initializations of the cache and returns a reference to it that is used as parameter to the other API functions.

Is called by the cache handling processes `init` function, hence putting the same requirements on it as a normal process `init` function. This function is called twice when starting the SSL application, once with the role client and once with the role server, as the SSL application must be prepared to take on both roles.

Includes property `{role, client | server}` in init argument list. Currently this is the only predefined property, there can also be user-defined properties. See also application environment variable session_cb_init_args.

Link to this callback

# lookup(CacheRef, Key)

View Source (since OTP R14B)

    -callback lookup(CacheRef, Key) -> Session
                        when
                            CacheRef :: session_cache_ref(),
                            Key :: session_cache_key(),
                            Session :: session() | undefined.

Looks up a cache entry. Is to be callable from any process.

Link to this callback

# select_session(CacheRef, Server)

View Source (optional) (since OTP R14B)

    -callback select_session(CacheRef, Server) -> Sessions
                                when
                                    CacheRef :: session_cache_ref(),
                                    Server :: {ssl:host(), inet:port_number()} | inet:port_number(),
                                    Sessions :: [session()].

Selects sessions that can be reused, that is sessions that include `PartialKey` in its key. Is to be callable from any process.

> #### Note

> Since OTP-23.3 This functions is only used on the client side and does not need to implemented for a server cache.

Link to this callback

# size(CacheRef)

View Source (since OTP 19.3)

    -callback size(CacheRef) -> Size when CacheRef :: session_cache_ref(), Size :: pos_integer().

Returns the number of sessions in the cache.

If size exceeds the maximum number of sessions, the current cache entries will be invalidated regardless of their remaining lifetime. Is to be callable from any process.

Link to this callback

# terminate(CacheRef)

View Source (since OTP R14B)

    -callback terminate(CacheRef) -> DoNotCare when CacheRef :: session_cache_ref(), DoNotCare :: any().

Takes care of possible cleanup that is needed when the cache handling process terminates.

Link to this callback

# update(CacheRef, Key, Session)

View Source (since OTP R14B)

    -callback update(CacheRef, Key, Session) -> DoNotCare
                        when
                            CacheRef :: session_cache_ref(),
                            Key :: session_cache_key(),
                            Session :: session() | undefined,
                            DoNotCare :: any().

Caches a new session or updates an already cached one.

Is only called from the cache handling process.