Class: ActiveRecord::ConnectionAdapters::QueryCache::QueryCacheRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/connection_adapters/abstract/query_cache.rb

Overview

Each connection pool has one of these registries. They map execution contexts to query cache stores.

The keys of the internal map are threads or fibers (whatever ActiveSupport::IsolatedExecutionState.context returns), and their associated values are their respective query cache stores.

Instance Method Summary collapse

Constructor Details

#initializeQueryCacheRegistry

:nodoc:



114
115
116
117
# File 'lib/active_record/connection_adapters/abstract/query_cache.rb', line 114

def initialize
  @mutex = Mutex.new
  @map = ConnectionPool::WeakThreadKeyMap.new
end

Instance Method Details

#clearObject



125
126
127
128
129
# File 'lib/active_record/connection_adapters/abstract/query_cache.rb', line 125

def clear
  @map.synchronize do
    @map.clear
  end
end

#compute_if_absent(context) ⇒ Object



119
120
121
122
123
# File 'lib/active_record/connection_adapters/abstract/query_cache.rb', line 119

def compute_if_absent(context)
  @map[context] || @mutex.synchronize do
    @map[context] ||= yield
  end
end