Class: ActiveRecord::ConnectionAdapters::ConnectionPool::WeakThreadKeyMap
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::ConnectionPool::WeakThreadKeyMap
- Defined in:
- lib/active_record/connection_adapters/abstract/connection_pool.rb
Overview
:nodoc:
Direct Known Subclasses
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #clear ⇒ Object
-
#initialize ⇒ WeakThreadKeyMap
constructor
FIXME: On 3.3 we could use ObjectSpace::WeakKeyMap but it currently causes GC crashes: https://github.com/byroot/rails/pull/3.
Constructor Details
#initialize ⇒ WeakThreadKeyMap
FIXME: On 3.3 we could use ObjectSpace::WeakKeyMap but it currently causes GC crashes: https://github.com/byroot/rails/pull/3
138 139 140 |
# File 'lib/active_record/connection_adapters/abstract/connection_pool.rb', line 138 def initialize @map = Concurrent::Map.new end |
Instance Method Details
#[](key) ⇒ Object
146 147 148 |
# File 'lib/active_record/connection_adapters/abstract/connection_pool.rb', line 146 def [](key) @map[key] end |
#[]=(key, value) ⇒ Object
150 151 152 153 154 155 |
# File 'lib/active_record/connection_adapters/abstract/connection_pool.rb', line 150 def []=(key, value) @map.each_pair do |thread, _| @map.delete(thread) unless thread&.alive? end @map[key] = value end |
#clear ⇒ Object
142 143 144 |
# File 'lib/active_record/connection_adapters/abstract/connection_pool.rb', line 142 def clear @map.clear end |