Class: Aikido::Zen::CacheEntry
- Inherits:
-
Object
- Object
- Aikido::Zen::CacheEntry
- Defined in:
- lib/aikido/zen/cache.rb
Constant Summary collapse
- DEFAULT_CLOCK =
-> { Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond) }
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #expired? ⇒ Boolean
- #initialize(value, ttl:, clock: nil) ⇒ Aikido::Zen::CacheEntry constructor
- #refresh ⇒ Object
Constructor Details
#initialize(value, ttl:, clock: nil) ⇒ Aikido::Zen::CacheEntry
75 76 77 78 79 80 81 |
# File 'lib/aikido/zen/cache.rb', line 75 def initialize(value, ttl:, clock: nil) @value = value @ttl = ttl @clock = clock || DEFAULT_CLOCK refresh end |
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
68 69 70 |
# File 'lib/aikido/zen/cache.rb', line 68 def value @value end |
Instance Method Details
#expired? ⇒ Boolean
87 88 89 |
# File 'lib/aikido/zen/cache.rb', line 87 def expired? @clock.call >= @expires end |
#refresh ⇒ Object
83 84 85 |
# File 'lib/aikido/zen/cache.rb', line 83 def refresh @expires = @clock.call + @ttl end |