Class: Profiler::Cluster::TokenCache
- Inherits:
-
Object
- Object
- Profiler::Cluster::TokenCache
- Defined in:
- lib/profiler/cluster/token_cache.rb
Constant Summary collapse
- TTL =
10 minutes
600
Instance Method Summary collapse
- #fetch(token) ⇒ Object
-
#initialize ⇒ TokenCache
constructor
A new instance of TokenCache.
- #invalidate(token) ⇒ Object
- #store(token, slave_name) ⇒ Object
Constructor Details
#initialize ⇒ TokenCache
Returns a new instance of TokenCache.
10 11 12 |
# File 'lib/profiler/cluster/token_cache.rb', line 10 def initialize @cache = Concurrent::Map.new end |
Instance Method Details
#fetch(token) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/profiler/cluster/token_cache.rb', line 14 def fetch(token) entry = @cache[token] return nil if entry.nil? || Time.now > entry[:expires_at] entry[:slave_name] end |
#invalidate(token) ⇒ Object
25 26 27 |
# File 'lib/profiler/cluster/token_cache.rb', line 25 def invalidate(token) @cache.delete(token) end |
#store(token, slave_name) ⇒ Object
21 22 23 |
# File 'lib/profiler/cluster/token_cache.rb', line 21 def store(token, slave_name) @cache[token] = { slave_name: slave_name, expires_at: Time.now + TTL } end |