Class: Autoscaler::CounterCacheMemory
- Inherits:
-
Object
- Object
- Autoscaler::CounterCacheMemory
- Defined in:
- lib/autoscaler/counter_cache_memory.rb
Overview
Implements a cache for the number of heroku works currently up Values are stored for short periods in the object
Defined Under Namespace
Classes: Expired
Instance Method Summary collapse
-
#counter ⇒ Object
Current value.
- #counter=(value) ⇒ Object
-
#initialize(timeout = 5) ⇒ CounterCacheMemory
constructor
A new instance of CounterCacheMemory.
Constructor Details
#initialize(timeout = 5) ⇒ CounterCacheMemory
Returns a new instance of CounterCacheMemory.
6 7 8 9 10 |
# File 'lib/autoscaler/counter_cache_memory.rb', line 6 def initialize(timeout = 5) @timeout = timeout @counter = 0 @valid_until = Time.now - 1 end |
Instance Method Details
#counter ⇒ Object
Current value. Uses the Hash#fetch api - pass a block to use in place of expired values or it will raise an exception.
22 23 24 25 26 |
# File 'lib/autoscaler/counter_cache_memory.rb', line 22 def counter return @counter if valid? return yield if block_given? raise Expired end |
#counter=(value) ⇒ Object
13 14 15 16 |
# File 'lib/autoscaler/counter_cache_memory.rb', line 13 def counter=(value) @valid_until = Time.now + @timeout @counter = value end |