Module: SlavePools::QueryCache

Included in:
ConnectionProxy
Defined in:
lib/slave_pools/query_cache.rb

Overview

duck-types with ActiveRecord::ConnectionAdapters::QueryCache but relies on ActiveRecord::Base.query_cache for state so we don’t fragment the cache across multiple connections

we could use more of ActiveRecord’s QueryCache if it only used accessors for its internal ivars.

Instance Method Summary collapse

Instance Method Details

#select_all(arel, name = nil, binds = []) ⇒ Object

select_all is trickier. it needs to use the master connection for cache logic, but ultimately pass its query through to whatever connection is current.



23
24
25
26
27
28
29
30
# File 'lib/slave_pools/query_cache.rb', line 23

def select_all(arel, name = nil, binds = [])
  if query_cache_enabled && !locked?(arel)
    sql = to_sql(arel, binds)
    cache_sql(sql, binds) { route_to(current, :select_all, sql, name, binds) }
  else
    route_to(current, :select_all, arel, name, binds)
  end
end