Class: ActiveSupport::WeakKeyMap
Do not use. This class is for internal use only.
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
|
Subclasses:
|
|
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
ObjectSpace::WeakKeyMap
|
|
|
Instance Chain:
self,
ObjectSpace::WeakKeyMap
|
|
| Inherits: | ObjectSpace::WeakKeyMap |
| Defined in: | activesupport/lib/active_support/weak_key_map.rb, activesupport/lib/active_support/weak_key_map.rb, activesupport/lib/active_support/weak_key_map.rb |
Class Method Summary
- .new ⇒ WeakKeyMap constructor
Instance Method Summary
- #[](key)
- #[]=(key, value)
- #clear
- #delete(key)
-
#fetch_or_store(key)
Returns the cached value, computing and storing it when nil.
Constructor Details
.new ⇒ WeakKeyMap
# File 'activesupport/lib/active_support/weak_key_map.rb', line 12
def initialize @map = ObjectSpace::WeakKeyMap.new @mutex = Mutex.new end
Instance Method Details
#[](key)
[ GitHub ]# File 'activesupport/lib/active_support/weak_key_map.rb', line 17
def [](key) @mutex.synchronize { @map[key] } end
#[]=(key, value)
[ GitHub ]# File 'activesupport/lib/active_support/weak_key_map.rb', line 21
def []=(key, value) @mutex.synchronize { @map[key] = value } end
#clear
[ GitHub ]# File 'activesupport/lib/active_support/weak_key_map.rb', line 29
def clear @mutex.synchronize { @map.clear } self end
#delete(key)
[ GitHub ]# File 'activesupport/lib/active_support/weak_key_map.rb', line 25
def delete(key) @mutex.synchronize { @map.delete(key) } end
#fetch_or_store(key)
Returns the cached value, computing and storing it when nil. This is not atomic: concurrent misses may double-compute and then return different values.
# File 'activesupport/lib/active_support/weak_key_map.rb', line 39
def fetch_or_store(key) value = self[key] return value unless value.nil? value = yield self[key] ||= value end