Module: Legion::Extensions::Agentic::Self::Identity::Helpers::TokenCache
- Defined in:
- lib/legion/extensions/agentic/self/identity/helpers/token_cache.rb
Constant Summary collapse
- REFRESH_BUFFER =
300
Class Method Summary collapse
- .approaching_expiry?(worker_id:, buffer: REFRESH_BUFFER) ⇒ Boolean
- .clear(worker_id:) ⇒ Object
- .clear_all ⇒ Object
- .fetch(worker_id:) ⇒ Object
- .store(worker_id:, token:, expires_in:) ⇒ Object
Class Method Details
.approaching_expiry?(worker_id:, buffer: REFRESH_BUFFER) ⇒ Boolean
37 38 39 40 41 42 43 44 |
# File 'lib/legion/extensions/agentic/self/identity/helpers/token_cache.rb', line 37 def approaching_expiry?(worker_id:, buffer: REFRESH_BUFFER) @mutex.synchronize do entry = @tokens[worker_id] return true unless entry (entry[:expires_at] - Time.now) < buffer end end |
.clear(worker_id:) ⇒ Object
46 47 48 |
# File 'lib/legion/extensions/agentic/self/identity/helpers/token_cache.rb', line 46 def clear(worker_id:) @mutex.synchronize { @tokens.delete(worker_id) } end |
.clear_all ⇒ Object
50 51 52 |
# File 'lib/legion/extensions/agentic/self/identity/helpers/token_cache.rb', line 50 def clear_all @mutex.synchronize { @tokens.clear } end |
.fetch(worker_id:) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/legion/extensions/agentic/self/identity/helpers/token_cache.rb', line 27 def fetch(worker_id:) @mutex.synchronize do entry = @tokens[worker_id] return nil unless entry return nil if Time.now >= entry[:expires_at] entry end end |
.store(worker_id:, token:, expires_in:) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/legion/extensions/agentic/self/identity/helpers/token_cache.rb', line 17 def store(worker_id:, token:, expires_in:) @mutex.synchronize do @tokens[worker_id] = { access_token: token, expires_at: Time.now + expires_in, acquired_at: Time.now } end end |