Module: Cash::ClassMethods

Defined in:
lib/cache_money.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(active_record_class) ⇒ Object



65
66
67
68
69
# File 'lib/cache_money.rb', line 65

def self.extended(active_record_class)
  class << active_record_class
    alias_method_chain :transaction, :cache_transaction
  end
end

Instance Method Details

#transaction_with_cache_transaction(*args, &block) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/cache_money.rb', line 71

def transaction_with_cache_transaction(*args, &block)
  if Cash.enabled
    # Wrap both the db and cache transaction in another cache transaction so that the cache 
    # gets written only after the database commit but can still flush the inner cache
    # transaction if an AR::Rollback is issued.
    Cash.repository.transaction do
      transaction_without_cache_transaction(*args) do
        Cash.repository.transaction { block.call }
      end
    end
  else
    transaction_without_cache_transaction(*args, &block)
  end
end