Class: Statsig::TTLSet
- Inherits:
-
Object
- Object
- Statsig::TTLSet
- Defined in:
- lib/ttl_set.rb
Instance Method Summary collapse
- #add(key) ⇒ Object
- #contains?(key) ⇒ Boolean
-
#initialize ⇒ TTLSet
constructor
A new instance of TTLSet.
- #periodic_reset ⇒ Object
- #shutdown ⇒ Object
Constructor Details
#initialize ⇒ TTLSet
Returns a new instance of TTLSet.
7 8 9 10 11 |
# File 'lib/ttl_set.rb', line 7 def initialize @store = Concurrent::Set.new @reset_interval = RESET_INTERVAL @background_reset = periodic_reset end |
Instance Method Details
#add(key) ⇒ Object
13 14 15 |
# File 'lib/ttl_set.rb', line 13 def add(key) @store.add(key) end |
#contains?(key) ⇒ Boolean
17 18 19 |
# File 'lib/ttl_set.rb', line 17 def contains?(key) @store.include?(key) end |
#periodic_reset ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/ttl_set.rb', line 25 def periodic_reset Thread.new do loop do sleep @reset_interval @store.clear end end end |
#shutdown ⇒ Object
21 22 23 |
# File 'lib/ttl_set.rb', line 21 def shutdown @background_reset&.exit end |