Skip to content

class Athena::HTTP::Session::Storage::Handler::File
inherits Athena::HTTP::Session::Storage::Handler::AbstractHandler #

A handler that stores each session in its own file, within the provided save_path directory.

Sessions are only shared between processes that have access to the same directory. Use a handler backed by a shared data store instead when running multiple servers.

Constructors#

.new(save_path : String = ::File.join(Dir.tempdir, "athena_sessions"), max_lifetime : Int32 = 1440)#

Creates a new handler storing sessions in the provided save_path directory, creating it if needed. Sessions expire once they were not used for max_lifetime seconds.

Raises an AHTTP::Exception::InvalidArgument if the directory is not owned by the current user, or its group or others have permissions on it. Otherwise they could read the session IDs from its file names, or add sessions of their own.

View source

Methods#

#gc(max_lifetime : Int32) : Int32#

Removes the sessions that were not used in the last max_lifetime seconds. Returns how many sessions were removed.

View source

#save_path : String#

Returns the directory sessions are stored in.

View source

#update_timestamp(session_id : String, data : String) : Bool#

Updates when the session with the provided session_id was last used, without changing its data. Returns true if it was updated, otherwise false.

Updates the session file's modification time, without creating it if it does not exist.

View source