Package org.springframework.session
Class MapSessionRepository
java.lang.Object
org.springframework.session.MapSessionRepository
- All Implemented Interfaces:
SessionRepository<MapSession>
A
SessionRepository backed by a Map and that uses a
MapSession. The injected Map can be backed by a distributed
NoSQL store like Hazelcast, for instance. Note that the supplied map itself is
responsible for purging the expired sessions.
The implementation does NOT support firing SessionDeletedEvent or
SessionExpiredEvent.
- Since:
- 1.0
-
Constructor Summary
ConstructorsConstructorDescriptionMapSessionRepository(Map<String, Session> sessions) Creates a new instance backed by the providedMap. -
Method Summary
Modifier and TypeMethodDescriptionCreates a newSessionthat is capable of being persisted by thisSessionRepository.voiddeleteById(String id) voidsave(MapSession session) Ensures theSessioncreated bySessionRepository.createSession()is saved.voidsetDefaultMaxInactiveInterval(Duration defaultMaxInactiveInterval) Set the maximum inactive interval in seconds between requests before newly created sessions will be invalidated.
-
Constructor Details
-
MapSessionRepository
- Parameters:
sessions- theMapto use. Cannot be null.
-
-
Method Details
-
setDefaultMaxInactiveInterval
Set the maximum inactive interval in seconds between requests before newly created sessions will be invalidated. A negative time indicates that the session will never time out. The default is 30 minutes.- Parameters:
defaultMaxInactiveInterval- the default maxInactiveInterval
-
save
Description copied from interface:SessionRepositoryEnsures theSessioncreated bySessionRepository.createSession()is saved.Some implementations may choose to save as the
Sessionis updated by returning aSessionthat immediately persists any changes. In this case, this method may not actually do anything.- Specified by:
savein interfaceSessionRepository<MapSession>- Parameters:
session- theSessionto save
-
findById
Description copied from interface:SessionRepository- Specified by:
findByIdin interfaceSessionRepository<MapSession>- Parameters:
id- theSession.getId()to lookup- Returns:
- the
Sessionby theSession.getId()or null if noSessionis found.
-
deleteById
Description copied from interface:SessionRepository- Specified by:
deleteByIdin interfaceSessionRepository<MapSession>- Parameters:
id- theSession.getId()to delete
-
createSession
Description copied from interface:SessionRepositoryCreates a newSessionthat is capable of being persisted by thisSessionRepository.This allows optimizations and customizations in how the
Sessionis persisted. For example, the implementation returned might keep track of the changes ensuring that only the delta needs to be persisted on a save.- Specified by:
createSessionin interfaceSessionRepository<MapSession>- Returns:
- a new
Sessionthat is capable of being persisted by thisSessionRepository
-