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.



113
114
115
116
117
# File 'lib/fluent/event_router.rb', line 113

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

Instance Method Details

#get(key) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/fluent/event_router.rb', line 119

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