class ElasticAPM::Util::LruCache
@api private
Public Class Methods
new(max_size = 512, &block)
click to toggle source
# File lib/elastic_apm/util/lru_cache.rb, line 6 def initialize(max_size = 512, &block) @max_size = max_size @data = Hash.new(&block) @mutex = Mutex.new end
Public Instance Methods
[](key)
click to toggle source
# File lib/elastic_apm/util/lru_cache.rb, line 12 def [](key) @mutex.synchronize do val = @data[key] return unless val add(key, val) val end end
[]=(key, val)
click to toggle source
# File lib/elastic_apm/util/lru_cache.rb, line 21 def []=(key, val) @mutex.synchronize do add(key, val) end end
length()
click to toggle source
# File lib/elastic_apm/util/lru_cache.rb, line 27 def length @data.length end
to_a()
click to toggle source
# File lib/elastic_apm/util/lru_cache.rb, line 31 def to_a @data.to_a end
Private Instance Methods
add(key, val)
click to toggle source
# File lib/elastic_apm/util/lru_cache.rb, line 37 def add(key, val) @data.delete(key) @data[key] = val return unless @data.length > @max_size @data.delete(@data.first[0]) end