Module: ArCache::ActiveRecord::ConnectionAdapters::Transaction
- Includes:
- NullTransaction
- Defined in:
- lib/ar_cache/active_record/connection_adapters/abstract/transaction.rb
Instance Method Summary collapse
- #add_changed_table(table_name) ⇒ Object
-
#commit ⇒ Object
FIXME: Cache update and transaction commit may cause dirty reads during this period!.
- #delete_ar_cache_keys(keys, delay: false) ⇒ Object
- #initialize ⇒ Object
- #read_uncommitted? ⇒ Boolean
- #update_ar_cache_table(table, delay: false) ⇒ Object
Instance Method Details
#add_changed_table(table_name) ⇒ Object
39 40 41 |
# File 'lib/ar_cache/active_record/connection_adapters/abstract/transaction.rb', line 39 def add_changed_table(table_name) connection.transaction_manager.add_changed_table(table_name) end |
#commit ⇒ Object
FIXME: Cache update and transaction commit may cause dirty reads during this period!
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ar_cache/active_record/connection_adapters/abstract/transaction.rb', line 44 def commit super ensure if @run_commit_callbacks @ar_cache_tables.uniq(&:name).each(&:update_version) if @ar_cache_tables.any? ArCache::Store.delete_multi(@ar_cache_keys.uniq) if @ar_cache_keys.any? else transaction = connection.current_transaction @ar_cache_tables.each { |table| transaction.update_ar_cache_table(table, delay: true) } transaction.delete_ar_cache_keys(@ar_cache_keys, delay: true) end end |
#delete_ar_cache_keys(keys, delay: false) ⇒ Object
27 28 29 30 |
# File 'lib/ar_cache/active_record/connection_adapters/abstract/transaction.rb', line 27 def delete_ar_cache_keys(keys, delay: false) super if !delay && read_uncommitted? @ar_cache_keys.push(*keys) end |
#initialize ⇒ Object
21 22 23 24 25 |
# File 'lib/ar_cache/active_record/connection_adapters/abstract/transaction.rb', line 21 def initialize(...) super @ar_cache_keys = [] @ar_cache_tables = [] end |
#read_uncommitted? ⇒ Boolean
57 58 59 60 61 |
# File 'lib/ar_cache/active_record/connection_adapters/abstract/transaction.rb', line 57 def read_uncommitted? ArCache::Configuration.read_uncommitted || isolation_level == :read_uncommitted || !connection.transaction_manager.fully_joinable? end |
#update_ar_cache_table(table, delay: false) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/ar_cache/active_record/connection_adapters/abstract/transaction.rb', line 32 def update_ar_cache_table(table, delay: false) add_changed_table(table.name) unless delay super if !delay && read_uncommitted? @ar_cache_tables.push(table) end |