Class: Parse::Authorization::SessionOwnerMap
- Inherits:
-
Object
- Object
- Parse::Authorization::SessionOwnerMap
- Defined in:
- lib/parse/authorization.rb
Overview
Process-local record of session objectId to owning user id, kept apart
from the identity plane so no session token can ever read a record.
Entries expire after ttl and the map holds at most MAX_ENTRIES,
dropping the oldest first. Values are stored typed
({"session_owner" => user_id}) so a shared store passed in its place
cannot confuse a record with an identity entry either.
Constant Summary collapse
- MAX_ENTRIES =
10_000
Instance Method Summary collapse
- #clear ⇒ Object
- #get(key) ⇒ Object
-
#initialize ⇒ SessionOwnerMap
constructor
A new instance of SessionOwnerMap.
- #invalidate(key) ⇒ Object
- #set(key, value, ttl:) ⇒ Object
Constructor Details
#initialize ⇒ SessionOwnerMap
Returns a new instance of SessionOwnerMap.
128 129 130 131 |
# File 'lib/parse/authorization.rb', line 128 def initialize @data = {} @mutex = Mutex.new end |
Instance Method Details
#clear ⇒ Object
157 158 159 |
# File 'lib/parse/authorization.rb', line 157 def clear @mutex.synchronize { @data.clear } end |
#get(key) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/parse/authorization.rb', line 133 def get(key) @mutex.synchronize do entry = @data[key] return nil if entry.nil? if entry[:expires_at] < Time.now @data.delete(key) return nil end entry[:value] end end |
#invalidate(key) ⇒ Object
153 154 155 |
# File 'lib/parse/authorization.rb', line 153 def invalidate(key) @mutex.synchronize { @data.delete(key) } end |
#set(key, value, ttl:) ⇒ Object
145 146 147 148 149 150 151 |
# File 'lib/parse/authorization.rb', line 145 def set(key, value, ttl:) @mutex.synchronize do @data.delete(key) @data[key] = { value: value, expires_at: Time.now + ttl } @data.shift while @data.size > MAX_ENTRIES end end |