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

Inherits:
Object
  • Object
show all
Defined in:
activerecord/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:



116
117
118
119
# File 'activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb', line 116

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

Instance Method Details

#clearObject



127
128
129
130
131
# File 'activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb', line 127

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

#compute_if_absent(context) ⇒ Object



121
122
123
124
125
# File 'activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb', line 121

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