Store API
Store(T) is the abstract base class for all storage backends. T must inherit from Session::Base and provide a parameterless constructor.
Abstract Methods
Subclasses must implement:
storage
: String
Backend name (e.g., "memory", "redis")
current_session
: T
Get current session
current_session=
(T)
Set current session
[]
(key : String) : T
Fetch session by ID (raises SessionNotFoundException)
[]?
(key : String) : T?
Fetch session by ID (returns nil)
[]=
(key : String, session : T) : T
Store a session
delete
(key : String)
Delete session by ID
size
: Int64
Count stored sessions
clear
Remove all sessions
Lifecycle Methods
create
: T
Create and store a new session. Triggers :started
delete
(no args)
Delete current session, create fresh one. Triggers :deleted
regenerate_id
: T
New ID, preserve data. Triggers on_regenerated
load_from
(HTTP::Cookies) : T?
Load session from request cookies. Triggers :loaded
set_cookies
(HTTP::Cookies, String) : Nil
Set session cookie on response. Triggers :client
Utility Methods
session_id
String
Current session's ID
valid?
Bool
Current session not expired?
flash
Flash
Flash message store
timeout
Time::Span
Configured session timeout
session_key
String
Cookie name (default "_session")
create_session_cookie
HTTP::Cookie
Build a session cookie for a host
Callbacks
on(event, session_id, session) dispatches to configured callbacks:
:started
on_started
(String, Session::Base) -> Nil
:loaded
on_loaded
(String, Session::Base) -> Nil
:client
on_client
(String, Session::Base) -> Nil
:deleted
on_deleted
(String, Session::Base) -> Nil
regenerate_id triggers on_regenerated directly with signature (String, String, Session::Base) -> Nil (old_id, new_id, session).
Concrete Implementations
MemoryStore -- In-memory, includes
QueryableStoreRedisStore -- Redis backend, includes
QueryableStoreCookieStore -- Client-side encrypted cookies
ClusteredRedisStore -- Redis + local cache + Pub/Sub
See Also
Session API --
Session::Baseclass referenceQuery Interface --
QueryableStore(T)methods
Last updated
Was this helpful?