Class: StackifyRubyAPM::Util::LruCache Private

Inherits:
Object
  • Object
show all
Defined in:
lib/stackify_apm/util/lru_cache.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initialize(max_size = 512, &block) ⇒ LruCache

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of LruCache.



7
8
9
10
11
# File 'lib/stackify_apm/util/lru_cache.rb', line 7

def initialize(max_size = 512, &block)
  @max_size = max_size
  @data = Hash.new(&block)
  @mutex = Mutex.new
end

Instance Method Details

#[](key) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



13
14
15
16
17
18
19
20
21
# File 'lib/stackify_apm/util/lru_cache.rb', line 13

def [](key)
  @mutex.synchronize do
    val = @data[key]
    return unless val

    add(key, val)
    val
  end
end

#[]=(key, val) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



23
24
25
26
27
# File 'lib/stackify_apm/util/lru_cache.rb', line 23

def []=(key, val)
  @mutex.synchronize do
    add(key, val)
  end
end

#lengthObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



29
30
31
# File 'lib/stackify_apm/util/lru_cache.rb', line 29

def length
  @data.length
end

#to_aObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



33
34
35
# File 'lib/stackify_apm/util/lru_cache.rb', line 33

def to_a
  @data.to_a
end