Krang::Session - session handling for Krang
use Krang::ClassLoader Session => qw(%session);
# get some session data
my $bang = $session{buck};
# get the session id
my $session_id = $session{_session_id};
# set from session data
$session{buck} = $bang + 1;
# delete from the session hash
delete $session{buck};
# it's that simple
This module provides access to a peristent hash per user session. This is available both in Apache/mod_perl, where a user session lasts from login to logout, and from shell scripts, where a user session lasts from process start to process end.
The session hash should be used for data that must persist between requests but is not permanent enough to be stored in the database. The most obvious usage is to maintain state while editing an object before eventually saving changes to the database.
NOTE The session hash should not be used as a general mechanism to speed up Krang. This is not a cache, it is an intermediary data store.
Sessions older than 24 hours are cleaned out daily by the scheduler. See Krang::Schedule::Action::clean for details.
Aside from the exported %session hash, the module supports the following routines.
$session_id = Krang::Session->create()
Create a new session and return the session id, to be used in a later
call to load(). After this call, %session is attached to the
new session.
Krang::Session->load($session_id)
Loads a session by id. After this call, %session is attached to
the specified session. If the session cannot be found, this routine
will croak().
$is_valid = Krang::Session->validate($session_id)
Validates a session by id, without loading it. Returns 1 if the session is valid and 0 if not.
Krang::Session->unload()
Unloads the current session, saving modified state to disk. If this routine is not called then the session will be saved the next time a session is loaded or when the process ends.
After this call, %session will be unavailable until the next call to
load().
Krang::Session->delete()
Krang::Session->delete($session_id)
Deletes a session from the store, permanently. A session id can be specified, or the current session will be deleted.