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



54
55
56
57
58
# File 'lib/cache_money.rb', line 54

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

Instance Method Details

#cacheable?(*args) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/cache_money.rb', line 75

def cacheable?(*args)
  true
end

#transaction_with_cache_transaction(*args) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/cache_money.rb', line 60

def transaction_with_cache_transaction(*args)
  if cache_config
    # 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.
    repository.transaction do
      transaction_without_cache_transaction(*args) do
        repository.transaction { yield }
      end
    end
  else
    transaction_without_cache_transaction(*args)
  end
end