Class: Zoreal::OAuth2::Client::MemoryCache
- Inherits:
-
Object
- Object
- Zoreal::OAuth2::Client::MemoryCache
- Defined in:
- lib/zoreal/oauth2/client.rb
Overview
The fallback JWKS cache: one process, TTL respected, no eviction beyond overwrite, because it only ever holds the one key set.
Instance Method Summary collapse
-
#initialize ⇒ MemoryCache
constructor
A new instance of MemoryCache.
- #read(key) ⇒ Object
- #write(key, value, expires_in:) ⇒ Object
Constructor Details
#initialize ⇒ MemoryCache
Returns a new instance of MemoryCache.
302 303 304 305 |
# File 'lib/zoreal/oauth2/client.rb', line 302 def initialize @mutex = Mutex.new @store = {} end |
Instance Method Details
#read(key) ⇒ Object
307 308 309 310 311 312 |
# File 'lib/zoreal/oauth2/client.rb', line 307 def read(key) @mutex.synchronize do value, expires_at = @store[key] expires_at && expires_at > Time.now ? value : nil end end |
#write(key, value, expires_in:) ⇒ Object
314 315 316 |
# File 'lib/zoreal/oauth2/client.rb', line 314 def write(key, value, expires_in:) @mutex.synchronize { @store[key] = [value, Time.now + expires_in] } end |