MemorySessionDAO

Simple memory-based implementation of the SessionDAO that stores all of its sessions in an in-memory {@link ConcurrentMap}. <b>This implementation does not page to disk and is therefore unsuitable for applications that could experience a large amount of sessions</b> and would therefore cause {@code OutOfMemoryException}s. It is <em>not</em> recommended for production use in most environments. <h2>Memory Restrictions</h2> If your application is expected to host many sessions beyond what can be stored in the memory available to the JVM, it is highly recommended to use a different {@code SessionDAO} implementation which uses a more expansive or permanent backing data store. <p/> In this case, it is recommended to instead use a custom {@link CachingSessionDAO} implementation that communicates with a higher-capacity data store of your choice (file system, database, etc). <h2>Changes in 1.0</h2> This implementation prior to 1.0 used to subclass the {@link CachingSessionDAO}, but this caused problems with many cache implementations that would expunge entries due to TTL settings, resulting in Sessions that would be randomly (and permanently) lost. The Shiro 1.0 release refactored this implementation to be 100% memory-based (without {@code Cache} usage to avoid this problem.

@see CachingSessionDAO

Constructors

this
this()
Undocumented in source.

Members

Functions

doCreate
string doCreate(Session session)
Undocumented in source. Be warned that the author may not have intended to support it.
doReadSession
Session doReadSession(string sessionId)
Undocumented in source. Be warned that the author may not have intended to support it.
getActiveSessions
Session[] getActiveSessions()
Undocumented in source. Be warned that the author may not have intended to support it.
remove
void remove(Session session)
Undocumented in source. Be warned that the author may not have intended to support it.
storeSession
Session storeSession(string id, Session session)
Undocumented in source. Be warned that the author may not have intended to support it.
update
void update(Session session)
Undocumented in source. Be warned that the author may not have intended to support it.

Inherited Members

From AbstractSessionDAO

getSessionIdGenerator
SessionIdGenerator getSessionIdGenerator()

Returns the {@code SessionIdGenerator} used by the {@link #generateSessionId(hunt.shiro.session.Session)} method. Unless overridden by the {@link #setSessionIdGenerator(SessionIdGenerator)} method, the default instance is a {@link JavaUuidSessionIdGenerator}.

setSessionIdGenerator
void setSessionIdGenerator(SessionIdGenerator sessionIdGenerator)

Sets the {@code SessionIdGenerator} used by the {@link #generateSessionId(hunt.shiro.session.Session)} method. Unless overridden by this method, the default instance ss a {@link JavaUuidSessionIdGenerator}.

generateSessionId
string generateSessionId(Session session)

Generates a new ID to be applied to the specified {@code session} instance. This method is usually called from within a subclass's {@link #doCreate} implementation where they assign the returned id to the session instance and then create a record with this ID in the EIS data store. <p/> Subclass implementations backed by EIS data stores that auto-generate IDs during record creation, such as relational databases, don't need to use this method or the {@link #getSessionIdGenerator() sessionIdGenerator} attribute - they can simply return the data store's generated ID from the {@link #doCreate} implementation if desired. <p/> This implementation uses the {@link #setSessionIdGenerator configured} {@link SessionIdGenerator} to create the ID.

create
string create(Session session)

Creates the session by delegating EIS creation to subclasses via the {@link #doCreate} method, and then asserting that the returned sessionId is not null.

assignSessionId
void assignSessionId(Session session, string sessionId)

Utility method available to subclasses that wish to assign a generated session ID to the session instance directly. This method is not used by the {@code AbstractSessionDAO} implementation directly, but it is provided so subclasses don't need to know the {@code Session} implementation if they don't need to. <p/> This default implementation casts the argument to a {@link SimpleSession}, Shiro's default EIS implementation.

doCreate
string doCreate(Session session)

Subclass hook to actually persist the given <tt>Session</tt> instance to the underlying EIS.

readSession
Session readSession(string sessionId)

Retrieves the Session object from the underlying EIS identified by <tt>sessionId</tt> by delegating to the {@link #doReadSession(java.io.Serializable)} method. If {@code null} is returned from that method, an {@link UnknownSessionException} will be thrown.

doReadSession
Session doReadSession(string sessionId)

Subclass implementation hook that retrieves the Session object from the underlying EIS or {@code null} if a session with that ID could not be found.

Meta