Module: ActiveCurrency::CacheableStore
- Includes:
- AfterCommitEverywhere
- Included in:
- RateStore
- Defined in:
- lib/active_currency/cacheable_store.rb
Overview
Mixin to add caching capability to a rate store when getting the current cache.
Instance Method Summary collapse
Instance Method Details
#add_rate(from, to, rate, date = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/active_currency/cacheable_store.rb', line 18 def add_rate(from, to, rate, date = nil) super return unless ActiveCurrency.configuration.cache_enabled? after_commit do Rails.cache.delete(cache_key(from, to)) end end |
#get_rate(from, to, date = nil) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/active_currency/cacheable_store.rb', line 9 def get_rate(from, to, date = nil) return super unless ActiveCurrency.configuration.cache_enabled? return super if date Rails.cache.fetch(cache_key(from, to), expires_in: 1.hour) do super end end |