Class: Datadog::OpenFeature::Exposures::Deduplicator

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/open_feature/exposures/deduplicator.rb

Overview

This class is a deduplication buffer based on LRU cache for exposure events

Constant Summary collapse

DEFAULT_CACHE_LIMIT =
1_000

Instance Method Summary collapse

Constructor Details

#initialize(limit: DEFAULT_CACHE_LIMIT) ⇒ Deduplicator



12
13
14
15
# File 'lib/datadog/open_feature/exposures/deduplicator.rb', line 12

def initialize(limit: DEFAULT_CACHE_LIMIT)
  @cache = Datadog::Core::Utils::LRUCache.new(limit)
  @mutex = Mutex.new
end

Instance Method Details

#duplicate?(key, value) ⇒ Boolean



17
18
19
20
21
22
23
24
25
26
# File 'lib/datadog/open_feature/exposures/deduplicator.rb', line 17

def duplicate?(key, value)
  @mutex.synchronize do
    stored = @cache[key]
    return true if stored == value

    @cache[key] = value
  end

  false
end