Explicit allow to enable / disable session cache

Motivation:

It is sometimes useful to enable / disable the session cache.

Modifications:

* Add OpenSslSessionContext.setSessionCacheEnabled(...) and isSessionCacheEnabled()

Result:

It is now possible to enable / disable cache on the fly
This commit is contained in:
Norman Maurer 2014-11-03 19:19:40 +01:00 committed by Norman Maurer
parent 8a1c7f2ca6
commit 8e6739ddc0
3 changed files with 31 additions and 0 deletions

View File

@ -214,5 +214,15 @@ public final class OpenSslClientContext extends OpenSslContext {
public int getSessionCacheSize() {
return 0;
}
@Override
public void setSessionCacheEnabled(boolean enabled) {
// ignored
}
@Override
public boolean isSessionCacheEnabled() {
return false;
}
}
}

View File

@ -319,5 +319,16 @@ public final class OpenSslServerContext extends OpenSslContext {
public int getSessionCacheSize() {
return (int) SSLContext.getSessionCacheSize(context);
}
@Override
public void setSessionCacheEnabled(boolean enabled) {
long mode = enabled ? SSL.SSL_SESS_CACHE_SERVER : SSL.SSL_SESS_CACHE_OFF;
SSLContext.setSessionCacheMode(context, mode);
}
@Override
public boolean isSessionCacheEnabled() {
return SSLContext.getSessionCacheMode(context) == SSL.SSL_SESS_CACHE_SERVER;
}
}
}

View File

@ -59,6 +59,16 @@ public abstract class OpenSslSessionContext implements SSLSessionContext {
SSLContext.setSessionTicketKeys(context, keys);
}
/**
* Enable or disable caching of SSL sessions.
*/
public abstract void setSessionCacheEnabled(boolean enabled);
/**
* Return {@code true} if caching of SSL sessions is enabled, {@code false} otherwise.
*/
public abstract boolean isSessionCacheEnabled();
/**
* Returns the stats of this context.
*/