class
Telecr::Session::MemoryStore
- Telecr::Session::MemoryStore
- Reference
- Object
Overview
MemoryStore stores session data in RAM with expiration Features:
- TTL (time-to-live) for automatic expiration
- Automatic cleanup of expired entries
- Disk backup to prevent data loss
Defined in:
session/memory_store.crConstructors
-
.new(default_ttl : Int32 = 300, cleanup_interval : Int32 = 300, backup_path : String | Nil = nil, backup_interval : Int32 = 60)
Initialize the store
Instance Method Summary
-
#auto_backup
Auto-backup if interval passed
-
#auto_cleanup
Auto-cleanup expired entries if interval passed
-
#backup!
Force a backup to disk
-
#cleanup
Remove all expired entries
-
#clear
Clear all data (both memory and disk)
-
#decrement(key, amount = 1, ttl = nil)
Decrement a numeric value
-
#delete(key)
Delete a key
-
#empty?
Check if store is empty
-
#exists?(key)
Check if key exists and not expired
-
#expire(key, ttl)
Set expiration for existing key
-
#expired?(key)
Check if a key has expired
-
#get(key)
Retrieve a value by key
-
#increment(key, amount = 1, ttl = nil)
Increment a numeric value
-
#keys
Get all non-expired keys
-
#load_from_disk
Load from disk on startup
-
#pattern_to_regex(pattern)
Convert glob pattern to regex
-
#restore!
Restore from disk
-
#scan(pattern = "*", count = 10)
Scan for keys matching a pattern (Redis-like)
-
#set(key, value, ttl = nil)
Store a value with optional TTL
-
#size
Get number of non-expired entries
-
#ttl(key)
Get remaining TTL for a key in seconds
Constructor Detail
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)
Instance Method Detail
Decrement a numeric value
@param key [String | Int | Int64] The session identifier @param amount [Int32] Amount to decrement by @return [Int32] New value
Delete a key
@param key [String | Int | Int64] The session identifier @return [Bool] True if deleted
Check if key exists and not expired
@param key [String | Int | Int64] The session identifier @return [Bool] True if exists and valid
Set expiration for existing key
@param key [String | Int | Int64] The session identifier @param ttl [Int32] Seconds until expiration @return [Bool] True if successful
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
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
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
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
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)