Class: Atatus::Util::LruCache Private
- Inherits:
-
Object
- Object
- Atatus::Util::LruCache
- Defined in:
- lib/atatus/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
- #[](key) ⇒ Object private
- #[]=(key, val) ⇒ Object private
-
#initialize(max_size = 512, &block) ⇒ LruCache
constructor
private
A new instance of LruCache.
- #length ⇒ Object private
- #to_a ⇒ Object private
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.
24 25 26 27 28 |
# File 'lib/atatus/util/lru_cache.rb', line 24 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.
30 31 32 33 34 35 36 37 |
# File 'lib/atatus/util/lru_cache.rb', line 30 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.
39 40 41 42 43 |
# File 'lib/atatus/util/lru_cache.rb', line 39 def []=(key, val) @mutex.synchronize do add(key, val) end end |
#length ⇒ 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.
45 46 47 |
# File 'lib/atatus/util/lru_cache.rb', line 45 def length @data.length end |
#to_a ⇒ 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.
49 50 51 |
# File 'lib/atatus/util/lru_cache.rb', line 49 def to_a @data.to_a end |