Module: IronBank::Cacheable::ClassMethods
- Defined in:
- lib/iron_bank/cacheable.rb
Overview
Override queryable class methods to use cache if present.
Instance Method Summary collapse
- #cache ⇒ Object
- #find(id, force: false) ⇒ Object
- #where(conditions, limit: IronBank::Actions::Query::DEFAULT_ZUORA_LIMIT) ⇒ Object
Instance Method Details
#cache ⇒ Object
49 50 51 |
# File 'lib/iron_bank/cacheable.rb', line 49 def cache IronBank.configuration.cache end |
#find(id, force: false) ⇒ Object
29 30 31 32 33 |
# File 'lib/iron_bank/cacheable.rb', line 29 def find(id, force: false) return super(id) unless cache cache.fetch(id, force: force) { super(id) } end |
#where(conditions, limit: IronBank::Actions::Query::DEFAULT_ZUORA_LIMIT) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/iron_bank/cacheable.rb', line 35 def where(conditions, limit: IronBank::Actions::Query::DEFAULT_ZUORA_LIMIT) # Conditions can be empty when called from #all, it does not make sense # to try to cache all records returned then. return super if conditions.empty? return super unless cache # Ensure we are not colliding when the conditions are similar for two # different resources, like Account and Subscription. cache_key = conditions.merge(object_name: name) cache.fetch(cache_key) { super } end |