Class: Philiprehberger::ExpiringMap::Entry
- Inherits:
-
Object
- Object
- Philiprehberger::ExpiringMap::Entry
- Defined in:
- lib/philiprehberger/expiring_map/entry.rb
Overview
Internal entry storing a value with its expiration time
Instance Attribute Summary collapse
-
#expires_at ⇒ Float
Monotonic time when the entry expires.
-
#value ⇒ Object
readonly
The stored value.
Instance Method Summary collapse
-
#expired? ⇒ Boolean
Check if the entry has expired.
-
#initialize(value, expires_at) ⇒ Entry
constructor
A new instance of Entry.
-
#ttl ⇒ Float
Return remaining TTL in seconds.
Constructor Details
#initialize(value, expires_at) ⇒ Entry
Returns a new instance of Entry.
9 10 11 12 |
# File 'lib/philiprehberger/expiring_map/entry.rb', line 9 def initialize(value, expires_at) @value = value @expires_at = expires_at end |
Instance Attribute Details
#expires_at ⇒ Float
Returns monotonic time when the entry expires.
18 19 20 |
# File 'lib/philiprehberger/expiring_map/entry.rb', line 18 def expires_at @expires_at end |
#value ⇒ Object (readonly)
Returns the stored value.
15 16 17 |
# File 'lib/philiprehberger/expiring_map/entry.rb', line 15 def value @value end |
Instance Method Details
#expired? ⇒ Boolean
Check if the entry has expired
23 24 25 |
# File 'lib/philiprehberger/expiring_map/entry.rb', line 23 def expired? Process.clock_gettime(Process::CLOCK_MONOTONIC) >= @expires_at end |
#ttl ⇒ Float
Return remaining TTL in seconds
30 31 32 33 |
# File 'lib/philiprehberger/expiring_map/entry.rb', line 30 def ttl remaining = @expires_at - Process.clock_gettime(Process::CLOCK_MONOTONIC) remaining.positive? ? remaining : 0.0 end |