Sha256: 49003238c647ffe170f5f6a19c0e0a7d9d40b6af01136c4d879e926282d31a9e
Contents?: true
Size: 1015 Bytes
Versions: 164
Compression:
Stored size: 1015 Bytes
Contents
# frozen_string_literal: true require 'concurrent' module SplitIoClient module Engine module Common TIME_INTERVAL_MS = 3600 * 1000 class ImpressionCounter DEFAULT_AMOUNT = 1 def initialize @cache = Concurrent::Hash.new end 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 pop_all to_return = Concurrent::Hash.new @cache.each do |key, value| to_return[key] = value end @cache.clear to_return end def make_key(split_name, time_frame) "#{split_name}::#{ImpressionCounter.truncate_time_frame(time_frame)}" end def self.truncate_time_frame(timestamp_ms) timestamp_ms - (timestamp_ms % TIME_INTERVAL_MS) end end end end end
Version data entries
164 entries across 164 versions & 1 rubygems