Class: Fluent::EventRouter::MatchCache

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/event_router.rb

Constant Summary collapse

MATCH_CACHE_SIZE =
1024

Instance Method Summary collapse

Constructor Details

#initializeMatchCache

Returns a new instance of MatchCache.



143
144
145
146
147
# File 'lib/fluent/event_router.rb', line 143

def initialize
  super
  @map = {}
  @keys = []
end

Instance Method Details

#get(key) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/fluent/event_router.rb', line 149

def get(key)
  if collector = @map[key]
    return collector
  end
  collector = @map[key] = yield
  if @keys.size >= MATCH_CACHE_SIZE
    # expire the oldest key
    @map.delete @keys.shift
  end
  @keys << key
  collector
end