Class: Heroic::LRUCache::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/heroic/lru_cache.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#keyObject (readonly)

Returns the value of attribute key.



106
107
108
# File 'lib/heroic/lru_cache.rb', line 106

def key
  @key
end

#leftObject

Returns the value of attribute left.



107
108
109
# File 'lib/heroic/lru_cache.rb', line 107

def left
  @left
end

#rightObject

Returns the value of attribute right.



107
108
109
# File 'lib/heroic/lru_cache.rb', line 107

def right
  @right
end

Instance Method Details

#readObject



112
113
114
# File 'lib/heroic/lru_cache.rb', line 112

def read
  @lock.synchronize { @value ||= yield(@key) }
end

#to_sObject



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