Class: ThreadSafeLru::Node
- Inherits:
-
Object
- Object
- ThreadSafeLru::Node
- Defined in:
- lib/threadsafe-lru/ThreadSafeLruCache.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #get_value(block) ⇒ Object
-
#initialize(key) ⇒ Node
constructor
A new instance of Node.
Constructor Details
#initialize(key) ⇒ Node
Returns a new instance of Node.
64 65 66 67 68 69 |
# File 'lib/threadsafe-lru/ThreadSafeLruCache.rb', line 64 def initialize key @key=key @produced=false @value=nil @lock=Mutex.new end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
71 72 73 |
# File 'lib/threadsafe-lru/ThreadSafeLruCache.rb', line 71 def key @key end |
Instance Method Details
#get_value(block) ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/threadsafe-lru/ThreadSafeLruCache.rb', line 73 def get_value block @lock.synchronize do unless (@produced) @value=block.call @key @produced=true end @value end end |