class SplitIoClient::Engine::Common::ImpressionCounter
def self.truncate_time_frame(timestamp_ms)
def self.truncate_time_frame(timestamp_ms) timestamp_ms - (timestamp_ms % TIME_INTERVAL_MS) end
def inc(split_name, time_frame)
def inc(split_name, time_frame) key = make_key(split_name, time_frame) current_amount = @cache[key] @cache[key] = current_amount.nil? ? DEFAULT_AMOUNT : (current_amount + DEFAULT_AMOUNT) end
def initialize
def initialize @cache = Concurrent::Hash.new end
def make_key(split_name, time_frame)
def make_key(split_name, time_frame) "#{split_name}::#{ImpressionCounter.truncate_time_frame(time_frame)}" end
def pop_all
def pop_all to_return = Concurrent::Hash.new @cache.each do |key, value| to_return[key] = value end @cache.clear to_return end