Description
Describe the bug
For a valid session, SessionRepositoryFilter.SessionRepositoryRequestWrapper.commitSession() does the following:
- Clears cached values for references for requestedSessionCache, requestedSession, and requestedSessionId.
- Saves the state of the session
- If the requested session ID is not valid, or if the ID of the session changed from the requested session ID, then the session ID is sent to the client
However, since #1 already cleared the requested session cached values #3 requires a completely redundant call to SessionRepository.findById(...). Depending on the implementation, this can be unnecessarily expensive.
To Reproduce
Use a tracer to detect calls to SessionRepository.findById(...). For a requested session, this is triggered twice, once at the beginning of the request, and again after the session is saved.
Expected behavior
SessionRepository.findById(...) should be considered a potentially expensive operation, and only triggered when necessary. Clearing cached values after determining whether to send the session ID to the client (i.e. in a finally block) would solve the problem.