Session::Store(T)
Inherits Reference < Object
Abstract base class for session storage backends
Generic Constraint: T must inherit from Session::Base T must provide a parameterless constructor (T.new)
Example usage:
class UserSession < Session::Base
property? authenticated : Bool = false
property user_id : Int64? = nil
end
# Use memory store for development
store = Session::MemoryStore(UserSession).new
# Use Redis for production
store = Session::RedisStore(UserSession).new(Redis.new)
Instance methods
Change the session's privileges (log in, switch user, elevate) and give it a new id in one step. Re-using the id a visitor had before logging in lets anyone who planted or observed it (session fixation) share the authenticated session.
store.authenticate { |session| session.user_id = user.id }
A cookie carrying the configured security attributes, expiring with the session timeout.
The session of the request being served. A store is shared by every request, so it is
kept per fiber: concurrent requests, and the next request on a keep-alive connection,
never see each other's session. SessionHandler calls release when a request ends.
A fiber spawned during a request starts with a blank session; capture the session
before spawn to use it there.
Whether this store encrypts sessions with Session.config.secret. Session.configure and
SessionHandler require a usable secret only when it does. The default follows
encrypt_redis_data (RedisStore, ClusteredRedisStore); a store that never encrypts
returns false (MemoryStore), and one that always does returns true (CookieStore).
Regenerate session ID while preserving session data Important for security after authentication state changes