New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #6752 DefaultSessionCache more extensible using ConcurrentMap #6753
Issue #6752 DefaultSessionCache more extensible using ConcurrentMap #6753
Conversation
DefaultSessionCache is designed to be extended, by virtue of its protected session map. Subclasses can set their own map instance instead. However the session map is specified as ConcurrentHashMap, when it only needs to be ConcurrentMap. Changed data type to ConcurrentMap to allow for wider options for subclasses, such as those wanted to use Caffeine's asMap() method which returns ConcurrentMap. Although changing to even more relaxed Map would work, that does not provide as much clarity that the map will be used concurrently - therefore used ConcurrentMap instead. Signed-off-by: Padraic Renaghan <padraic@renaghan.com>
Presumably, if accepted, you'll want this change on 11.0.x branch as well. Let me know if that happens automatically or if you want me to open separate issue/PR for the 11.0.x branch. |
Here is an example of how I am trying to extend
|
@prenagha Typically we just merge forward changes from 10 to 11. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks
@prenagha I don't have any problem with a ConcurrentMap instead of a ConcurrentHashMap. However, are you sure you want to be subclassing the DefaultSessionCache, and that what you're not looking for is actually making an L2 cache for session data https://www.eclipse.org/jetty/documentation/jetty-10/programming-guide/index.html#pg-server-session-cachingsessiondatastore? Alternatively, there's a lot of different expiry behaviour you can configure on the DefaultSessionCache without necessarily subclassing, eg: https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/session/AbstractSessionCache.html#setEvictionPolicy(int). That said, you are more than welcome to extend the DefaultSessionCache any way you want, I just want to make sure you've considered all the stuff that's available out-of-the-box ;) |
I don't like the example usage of calling I think I would have preferred the API to set the map as a constructor. ala. public class SessionExpiringNearCache extends DefaultSessionCache {
private final Cache<String, Session> nearCache =
Caffeine.newBuilder()
.expireAfterAccess(15, TimeUnit.MINUTES)
.build();
public SessionNearCache(SessionHandler manager) {
super(manager, nearCache.asMap());
}
} or as a or at at the very least as a proper (protected) setter method |
@janbartel thanks for the pointers on Probably will end up using default for L1, but am experimenting with some additional options that Caffeine provides to see if useful. For the L2 Redis backend, if you have a pointer to an existing implementation that is widely used let me know. Otherwise was going to use |
@joakime I agree that extensibility could be better done. However I was just trying to follow the lead of
|
I just took a look at the code in |
DefaultSessionCache is designed to be extended, by virtue of its protected session map. Subclasses can set their own map instance instead. However the session map is specified as ConcurrentHashMap, when it only needs to be ConcurrentMap.
Changed data type to ConcurrentMap to allow for wider options for subclasses, such as those wanted to use Caffeine's asMap() method which returns ConcurrentMap.
Although changing to even more relaxed Map would work, that does not provide as much clarity that the map will be used concurrently - therefore used ConcurrentMap instead.
Resolves #6752
Signed-off-by: Padraic Renaghan padraic@renaghan.com