Class: Aws::LRUCache Private
- Inherits:
- 
      Object
      
        - Object
- Aws::LRUCache
 
- Defined in:
- lib/aws-sdk-core/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 simple thread safe LRU cache
Defined Under Namespace
Classes: Entry
Instance Method Summary collapse
- #[](key) ⇒ Object private
- #[]=(key, value) ⇒ Object private
- #clear ⇒ Object private
- 
  
    
      #initialize(options = {})  ⇒ LRUCache 
    
    
  
  
  
    constructor
  
  
  
  
  
  private
  
    A new instance of LRUCache. 
- #key?(key) ⇒ Boolean private
Constructor Details
#initialize(options = {}) ⇒ 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.
| 10 11 12 13 14 15 | # File 'lib/aws-sdk-core/lru_cache.rb', line 10 def initialize( = {}) @max_entries = [:max_entries] || 100 @expiration = [:expiration] @entries = {} @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.
| 19 20 21 22 23 24 25 26 27 28 | # File 'lib/aws-sdk-core/lru_cache.rb', line 19 def [](key) @mutex.synchronize do value = @entries[key] if value @entries.delete(key) @entries[key] = value unless value.expired? end @entries[key]&.value end end | 
#[]=(key, 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.
| 32 33 34 35 36 37 38 39 40 | # File 'lib/aws-sdk-core/lru_cache.rb', line 32 def []=(key, value) @mutex.synchronize do @entries.shift unless @entries.size < @max_entries # delete old value if exists @entries.delete(key) @entries[key] = Entry.new(value: value, expiration: @expiration) @entries[key].value end 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.
| 51 52 53 54 55 | # File 'lib/aws-sdk-core/lru_cache.rb', line 51 def clear @mutex.synchronize do @entries.clear end end | 
#key?(key) ⇒ Boolean
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.
| 44 45 46 47 48 49 | # File 'lib/aws-sdk-core/lru_cache.rb', line 44 def key?(key) @mutex.synchronize do @entries.delete(key) if @entries.key?(key) && @entries[key].expired? @entries.key?(key) end end |