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.cr

Constructors

Instance Method Summary

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

def self.new #

[View source]

Instance Method Detail

def batch(session_id : String, &block : BatchOperations -> ) : Nil #

Performs bulk operations atomically


[View source]
def batch_set(session_id : String, hash : Hash(String, String)) : Nil #

Efficiently sets multiple key-value pairs in a single atomic operation


[View source]
def delete(session_id : String, key : String) : Nil #

Deletes a specific key from a session


[View source]
def destroy(session_id : String) : Nil #

Completely destroys a session and all its data


[View source]
def empty?(session_id : String) : Bool #

Checks if the session is empty


[View source]
def exists?(session_id : String, key : String) : Bool #

Checks if a key exists in the given session


[View source]
def expire(session_id : String, seconds : Int32) : Nil #

Sets an expiration time for the session


[View source]
def get(session_id : String, key : String) : String | Nil #

Retrieves a value for the given session and key


[View source]
def keys(session_id : String) : Array(String) #

Returns all keys for the given session


[View source]
def set(session_id : String, key : String, value : String) : Nil #

Sets a value for the given session and key


[View source]
def to_hash(session_id : String) : Hash(String, String) #

Returns all session data as a hash


[View source]
def values(session_id : String) : Array(String) #

Returns all values for the given session


[View source]