class
Amber::Adapters::MemorySessionAdapter
Overview
In-memory implementation of SessionAdapter.
This adapter stores session data in memory using Hash structures and provides TTL functionality through background cleanup. This is the default session adapter and is suitable for development, testing, and single-instance applications.
Note: Session data will be lost when the application restarts since everything is stored in memory. For production applications that require persistence or multi-instance deployments, consider using a database or Redis-based adapter.
Usage
# Configure in your application settings
config.session_adapter = Amber::Adapters::MemorySessionAdapter.new
Defined in:
amber/adapters/memory_session_adapter.crConstructors
Instance Method Summary
-
#batch(session_id : String, &block : BatchOperations -> ) : Nil
Performs bulk operations atomically
-
#batch_set(session_id : String, hash : Hash(String, String)) : Nil
Efficiently sets multiple key-value pairs in a single atomic operation
-
#delete(session_id : String, key : String) : Nil
Deletes a specific key from a session
-
#destroy(session_id : String) : Nil
Completely destroys a session and all its data
-
#empty?(session_id : String) : Bool
Checks if the session is empty
-
#exists?(session_id : String, key : String) : Bool
Checks if a key exists in the given session
-
#expire(session_id : String, seconds : Int32) : Nil
Sets an expiration time for the session
-
#get(session_id : String, key : String) : String | Nil
Retrieves a value for the given session and key
-
#keys(session_id : String) : Array(String)
Returns all keys for the given session
-
#set(session_id : String, key : String, value : String) : Nil
Sets a value for the given session and key
-
#to_hash(session_id : String) : Hash(String, String)
Returns all session data as a hash
-
#values(session_id : String) : Array(String)
Returns all values for the given session
Instance methods inherited from class Amber::Adapters::SessionAdapter
batch(session_id : String, &block : SessionBatchOperations -> ) : Nil
batch,
batch_set(session_id : String, hash : Hash(String, String)) : Nil
batch_set,
close : Nil
close,
delete(session_id : String, key : String) : Nil
delete,
destroy(session_id : String) : Nil
destroy,
empty?(session_id : String) : Bool
empty?,
exists?(session_id : String, key : String) : Bool
exists?,
expire(session_id : String, seconds : Int32) : Nil
expire,
get(session_id : String, key : String) : String | Nil
get,
healthy? : Bool
healthy?,
keys(session_id : String) : Array(String)
keys,
set(session_id : String, key : String, value : String) : Nil
set,
to_hash(session_id : String) : Hash(String, String)
to_hash,
values(session_id : String) : Array(String)
values
Constructor Detail
Instance Method Detail
Performs bulk operations atomically
Efficiently sets multiple key-value pairs in a single atomic operation
Deletes a specific key from a session
Completely destroys a session and all its data
Checks if a key exists in the given session
Sets an expiration time for the session
Retrieves a value for the given session and key
Returns all keys for the given session
Sets a value for the given session and key
Returns all session data as a hash
Returns all values for the given session