module ArCache::ActiveRecord::ConnectionAdapters::Transaction

Attributes

ar_cache_primary_keys[R]
ar_cache_tables[R]

Public Class Methods

new(...) click to toggle source
Calls superclass method
# File lib/ar_cache/active_record/connection_adapters/abstract/transaction.rb, line 29
def initialize(...)
  super
  @ar_cache_primary_keys = []
  @ar_cache_tables = []
end

Public Instance Methods

commit() click to toggle source

FIXME: The cache is removed after transaction commited, so dirty read may occur.

Calls superclass method
# File lib/ar_cache/active_record/connection_adapters/abstract/transaction.rb, line 52
def commit
  super
ensure
  if @run_commit_callbacks
    handle_ar_cache_primary_keys(ar_cache_primary_keys.uniq) if ar_cache_primary_keys.any?
    ar_cache_tables.uniq(&:name).each(&:update_cache) if ar_cache_tables.any?
  else
    connection.current_transaction.ar_cache_tables.push(*ar_cache_tables)
    connection.current_transaction.ar_cache_primary_keys.push(*ar_cache_primary_keys)
  end
end
delete_ar_cache_primary_keys(keys, table) click to toggle source
# File lib/ar_cache/active_record/connection_adapters/abstract/transaction.rb, line 35
def delete_ar_cache_primary_keys(keys, table)
  connection.transaction_manager.add_transaction_table(table.name)
  return if table.disabled?

  super if read_uncommitted?
  ar_cache_primary_keys.push(*keys)
end
read_uncommitted?() click to toggle source
# File lib/ar_cache/active_record/connection_adapters/abstract/transaction.rb, line 64
def read_uncommitted?
  isolation_level == :read_uncommitted || !connection.transaction_manager.fully_joinable?
end
update_ar_cache_table(table) click to toggle source
# File lib/ar_cache/active_record/connection_adapters/abstract/transaction.rb, line 43
def update_ar_cache_table(table)
  connection.transaction_manager.add_transaction_table(table.name)
  return if table.disabled?

  super if read_uncommitted?
  ar_cache_tables.push(table)
end