• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2018 gRPC authors.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""gRPC's APIs for TLS Session Resumption support"""
15
16from grpc._cython import cygrpc as _cygrpc
17
18
19def ssl_session_cache_lru(capacity):
20    """Creates an SSLSessionCache with LRU replacement policy
21
22    Args:
23      capacity: Size of the cache
24
25    Returns:
26      An SSLSessionCache with LRU replacement policy that can be passed as a value for
27      the grpc.ssl_session_cache option to a grpc.Channel. SSL session caches are used
28      to store session tickets, which clients can present to resume previous TLS sessions
29      with a server.
30    """
31    return SSLSessionCache(_cygrpc.SSLSessionCacheLRU(capacity))
32
33
34class SSLSessionCache(object):
35    """An encapsulation of a session cache used for TLS session resumption.
36
37    Instances of this class can be passed to a Channel as values for the
38    grpc.ssl_session_cache option
39    """
40
41    def __init__(self, cache):
42        self._cache = cache
43
44    def __int__(self):
45        return int(self._cache)
46