Class: LaunchDarkly::Impl::SimpleLRUCacheSet Private
- Inherits:
-
Object
- Object
- LaunchDarkly::Impl::SimpleLRUCacheSet
- Defined in:
- lib/ldclient-rb/impl/simple_lru_cache.rb
Overview
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.
A non-thread-safe implementation of a LRU cache set with only add and reset methods. Based on https://github.com/SamSaffron/lru_redux/blob/master/lib/lru_redux/cache.rb
Instance Method Summary collapse
-
#add(value) ⇒ Object
private
Adds a value to the cache or marks it recent if it was already there.
- #clear ⇒ Object private
-
#initialize(capacity) ⇒ SimpleLRUCacheSet
constructor
private
A new instance of SimpleLRUCacheSet.
Constructor Details
#initialize(capacity) ⇒ SimpleLRUCacheSet
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 SimpleLRUCacheSet.
7 8 9 10 |
# File 'lib/ldclient-rb/impl/simple_lru_cache.rb', line 7 def initialize(capacity) @values = {} @capacity = capacity end |
Instance Method Details
#add(value) ⇒ 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.
Adds a value to the cache or marks it recent if it was already there. Returns true if already there.
13 14 15 16 17 18 19 |
# File 'lib/ldclient-rb/impl/simple_lru_cache.rb', line 13 def add(value) found = true @values.delete(value) { found = false } @values[value] = true @values.shift if @values.length > @capacity found end |
#clear ⇒ 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.
21 22 23 |
# File 'lib/ldclient-rb/impl/simple_lru_cache.rb', line 21 def clear @values = {} end |