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
ConstructorDescriptionMapSessionRepository
(Map<String, Session> sessions) Creates a new instance backed by the providedMap
. -
Method Summary
Modifier and TypeMethodDescriptionCreates a newSession
that is capable of being persisted by thisSessionRepository
.void
deleteById
(String id) void
save
(MapSession session) Ensures theSession
created bySessionRepository.createSession()
is saved.void
setDefaultMaxInactiveInterval
(Duration defaultMaxInactiveInterval) Set the maximum inactive interval in seconds between requests before newly created sessions will be invalidated.
-
Constructor Details
-
MapSessionRepository
- Parameters:
sessions
- theMap
to 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:SessionRepository
Ensures theSession
created bySessionRepository.createSession()
is saved.Some implementations may choose to save as the
Session
is updated by returning aSession
that immediately persists any changes. In this case, this method may not actually do anything.- Specified by:
save
in interfaceSessionRepository<MapSession>
- Parameters:
session
- theSession
to save
-
findById
Description copied from interface:SessionRepository
- Specified by:
findById
in interfaceSessionRepository<MapSession>
- Parameters:
id
- theSession.getId()
to lookup- Returns:
- the
Session
by theSession.getId()
or null if noSession
is found.
-
deleteById
Description copied from interface:SessionRepository
- Specified by:
deleteById
in interfaceSessionRepository<MapSession>
- Parameters:
id
- theSession.getId()
to delete
-
createSession
Description copied from interface:SessionRepository
Creates a newSession
that is capable of being persisted by thisSessionRepository
.This allows optimizations and customizations in how the
Session
is 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:
createSession
in interfaceSessionRepository<MapSession>
- Returns:
- a new
Session
that is capable of being persisted by thisSessionRepository
-