class Fluent::Plugin::KubeletMetadata::ThreadsafeLruCache

Public Class Methods

new(size) click to toggle source
# File lib/fluent/plugin/filter_kubelet_metadata.rb, line 30
def initialize(size)
  @size = size
  @data = {}
  @mutex = Mutex.new
end

Public Instance Methods

[](key) click to toggle source
# File lib/fluent/plugin/filter_kubelet_metadata.rb, line 36
def [](key)
  @mutex.synchronize do
    value = @data.delete(key) # always remove ... later add it back if necessary
    return if value.nil? # miss
    @data[key] = value # mark as recently used
  end
end
[]=(key, value) click to toggle source
# File lib/fluent/plugin/filter_kubelet_metadata.rb, line 44
def []=(key, value)
  @mutex.synchronize do
    @data.delete @data.first[0] if @data.size == @size # make room
    @data[key] = value
  end
end