Class: Heroic::LRUCache::Node
- Inherits:
-
Object
- Object
- Heroic::LRUCache::Node
- Defined in:
- lib/heroic/lru_cache.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#left ⇒ Object
Returns the value of attribute left.
-
#right ⇒ Object
Returns the value of attribute right.
Instance Method Summary collapse
-
#initialize(key) ⇒ Node
constructor
A new instance of Node.
- #read ⇒ Object
- #to_s ⇒ Object
- #write(value) ⇒ Object
Constructor Details
#initialize(key) ⇒ Node
Returns a new instance of Node.
108 109 110 111 |
# File 'lib/heroic/lru_cache.rb', line 108 def initialize(key) @key = key @lock = Mutex.new end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
106 107 108 |
# File 'lib/heroic/lru_cache.rb', line 106 def key @key end |
#left ⇒ Object
Returns the value of attribute left.
107 108 109 |
# File 'lib/heroic/lru_cache.rb', line 107 def left @left end |
#right ⇒ Object
Returns the value of attribute right.
107 108 109 |
# File 'lib/heroic/lru_cache.rb', line 107 def right @right end |
Instance Method Details
#read ⇒ Object
112 113 114 |
# File 'lib/heroic/lru_cache.rb', line 112 def read @lock.synchronize { @value ||= yield(@key) } end |
#to_s ⇒ Object
118 119 120 |
# File 'lib/heroic/lru_cache.rb', line 118 def to_s sprintf '<Node:%x(%s)>', self.object_id, @key.inspect end |
#write(value) ⇒ Object
115 116 117 |
# File 'lib/heroic/lru_cache.rb', line 115 def write(value) @lock.synchronize { @value = value } end |