Class: MixinBot::SessionStore

Inherits:
Object
  • Object
show all
Defined in:
lib/mixin_bot/session_store.rb

Overview

In-memory cache of recipient sessions for encrypted-message sending.

Mirrors the Go SDK's MapSessionStore: fetch returns the cached session list for a recipient user (or nil on a miss) and store overwrites it; storing nil evicts the entry (used when sessions expire mid-send). Any object answering both calls can be passed as session_store: to API#post_encrypted_messages to plug in custom caching (e.g. Redis, TTLs).

Instance Method Summary collapse

Constructor Details

#initialize ⇒ SessionStore

Returns a new instance of SessionStore.



14
15
16
# File 'lib/mixin_bot/session_store.rb', line 14

def initialize
  @sessions = {}
end

Instance Method Details

#fetch(user_id) ⇒ Object



18
19
20
# File 'lib/mixin_bot/session_store.rb', line 18

def fetch(user_id)
  @sessions[user_id]
end

#store(user_id, sessions) ⇒ Object



22
23
24
# File 'lib/mixin_bot/session_store.rb', line 22

def store(user_id, sessions)
  @sessions[user_id] = sessions
end