class Telecr::Session::MemoryStore

Overview

MemoryStore stores session data in RAM with expiration Features:

Defined in:

session/memory_store.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(default_ttl : Int32 = 300, cleanup_interval : Int32 = 300, backup_path : String | Nil = nil, backup_interval : Int32 = 60) #

Initialize the store

@param default_ttl [Int32] Default time-to-live in seconds (default: 300) @param cleanup_interval [Int32] How often to clean expired entries (default: 300) @param backup_path [String?] Path to save backup file (nil = no backup) @param backup_interval [Int32] How often to save backup in seconds (default: 60)


[View source]

Instance Method Detail

def auto_backup #

Auto-backup if interval passed


[View source]
def auto_cleanup #

Auto-cleanup expired entries if interval passed


[View source]
def backup! #

Force a backup to disk


[View source]
def cleanup #

Remove all expired entries


[View source]
def clear #

Clear all data (both memory and disk)


[View source]
def decrement(key, amount = 1, ttl = nil) #

Decrement a numeric value

@param key [String | Int | Int64] The session identifier @param amount [Int32] Amount to decrement by @return [Int32] New value


[View source]
def delete(key) #

Delete a key

@param key [String | Int | Int64] The session identifier @return [Bool] True if deleted


[View source]
def empty? #

Check if store is empty

@return [Bool] True if no valid entries


[View source]
def exists?(key) #

Check if key exists and not expired

@param key [String | Int | Int64] The session identifier @return [Bool] True if exists and valid


[View source]
def expire(key, ttl) #

Set expiration for existing key

@param key [String | Int | Int64] The session identifier @param ttl [Int32] Seconds until expiration @return [Bool] True if successful


[View source]
def expired?(key) #

Check if a key has expired


[View source]
def get(key) #

Retrieve a value by key

@param key [String | Int | Int64] The session identifier @return [JSON::Any?] The stored value or nil if not found/expired


[View source]
def increment(key, amount = 1, ttl = nil) #

Increment a numeric value

@param key [String | Int | Int64] The session identifier @param amount [Int32] Amount to increment by @param ttl [Int32?] Optional TTL for the key @return [Int32] New value


[View source]
def keys #

Get all non-expired keys

@return [Array(String)] List of valid keys


[View source]
def load_from_disk #

Load from disk on startup


[View source]
def pattern_to_regex(pattern) #

Convert glob pattern to regex


[View source]
def restore! #

Restore from disk


[View source]
def scan(pattern = "*", count = 10) #

Scan for keys matching a pattern (Redis-like)

@param pattern [String] Pattern with * and ? wildcards @param count [Int32] Maximum number of keys to return @return [Array(String)] Matching keys


[View source]
def set(key, value, ttl = nil) #

Store a value with optional TTL

@param key [String | Int | Int64] The session identifier @param value [JSON::Any] The data to store @param ttl [Int32?] Time-to-live in seconds (nil = use default) @return [JSON::Any] The stored value


[View source]
def size #

Get number of non-expired entries

@return [Int32] Size of store


[View source]
def ttl(key) #

Get remaining TTL for a key in seconds

@param key [String | Int | Int64] The session identifier @return [Int32] Seconds remaining (-1 if expired or not found)


[View source]