Class: MultiSessionCacheStore

Inherits:
ActionDispatch::Session::AbstractStore
  • Object
show all
Defined in:
lib/multi_session_cache_store.rb

Constant Summary collapse

VERSION =
"0.1.1"

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ MultiSessionCacheStore



4
5
6
7
8
9
10
# File 'lib/multi_session_cache_store.rb', line 4

def initialize(app, options = {})
  @cache = options[:cache] || Rails.cache
  options[:expire_after] ||= @cache.options[:expires_in]
  @param = options[:param]
  @serializer = options[:serializer]
  super
end

Instance Method Details

#delete_session(env, sid, options) ⇒ Object



28
29
30
31
# File 'lib/multi_session_cache_store.rb', line 28

def delete_session(env, sid, options)
  @cache.delete(cache_key(env, sid))
  sid
end

#find_session(env, sid) ⇒ Object



12
13
14
15
16
# File 'lib/multi_session_cache_store.rb', line 12

def find_session(env, sid)
  sid ||= generate_sid
  session = @serializer.parse(@cache.read(cache_key(env, sid)) || "{}")
  [sid, session]
end

#write_session(env, sid, session, options) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/multi_session_cache_store.rb', line 18

def write_session(env, sid, session, options)
  key = cache_key(env, sid)
  if session
    @cache.write(key, @serializer.dump(session), expires_in: options[:expire_after])
  else
    @cache.delete(key)
  end
  sid
end