Class: Tofu::SessionBar

Inherits:
Object
  • Object
show all
Includes:
MonitorMixin
Defined in:
lib/tofu.rb

Instance Method Summary collapse

Constructor Details

#initializeSessionBar

Returns a new instance of SessionBar.



84
85
86
87
88
89
# File 'lib/tofu.rb', line 84

def initialize
  super()
  @pool = {}
  @keeper = keeper
  @interval = 60
end

Instance Method Details

#fetch(key) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/tofu.rb', line 100

def fetch(key)
  return nil if key.nil?
  synchronize do
    session = @pool[key]
    return nil unless session
    if session.expired?
      @pool.delete(key)
      return nil
    end
    return session
  end
end

#store(session) ⇒ Object



91
92
93
94
95
96
97
98
# File 'lib/tofu.rb', line 91

def store(session)
  key = session.session_id
  synchronize do
    @pool[key] = session
  end
  @keeper.wakeup
  return key
end