FileDocCategorySizeDatePackage
SSLSessionCache.javaAPI DocAndroid 5.1 API3985Thu Mar 12 22:22:10 GMT 2015android.net

SSLSessionCache

public final class SSLSessionCache extends Object
File-based cache of established SSL sessions. When re-establishing a connection to the same server, using an SSL session cache can save some time, power, and bandwidth by skipping directly to an encrypted stream. This is a persistent cache which can span executions of the application.
see
SSLCertificateSocketFactory

Fields Summary
private static final String
TAG
final com.android.org.conscrypt.SSLClientSessionCache
mSessionCache
Constructors Summary
public SSLSessionCache(Object cache)
NOTE: This needs to be Object (and not SSLClientSessionCache) because apps that build directly against the framework (and not the SDK) might not declare a dependency on conscrypt. Javac will then has fail while resolving constructors.

hide
For unit test use only

        mSessionCache = (SSLClientSessionCache) cache;
    
public SSLSessionCache(File dir)
Create a session cache using the specified directory. Individual session entries will be files within the directory. Multiple instances for the same directory share data internally.

param
dir to store session files in (created if necessary)
throws
IOException if the cache can't be opened

        mSessionCache = FileClientSessionCache.usingDirectory(dir);
    
public SSLSessionCache(android.content.Context context)
Create a session cache at the default location for this app. Multiple instances share data internally.

param
context for the application

        File dir = context.getDir("sslcache", Context.MODE_PRIVATE);
        SSLClientSessionCache cache = null;
        try {
            cache = FileClientSessionCache.usingDirectory(dir);
        } catch (IOException e) {
            Log.w(TAG, "Unable to create SSL session cache in " + dir, e);
        }
        mSessionCache = cache;
    
Methods Summary
public static voidinstall(android.net.SSLSessionCache cache, javax.net.ssl.SSLContext context)
Installs a {@link SSLSessionCache} on a {@link SSLContext}. The cache will be used on all socket factories created by this context (including factories created before this call).

param
cache the cache instance to install, or {@code null} to uninstall any existing cache.
param
context the context to install it on.
throws
IllegalArgumentException if the context does not support a session cache.
hide
candidate for public API


                                                                                           
           
        SSLSessionContext clientContext = context.getClientSessionContext();
        if (clientContext instanceof ClientSessionContext) {
            ((ClientSessionContext) clientContext).setPersistentCache(
                    cache == null ? null : cache.mSessionCache);
        } else {
            throw new IllegalArgumentException("Incompatible SSLContext: " + context);
        }