module IronBank::Cacheable::ClassMethods

Override queryable class methods to use cache if present.

Public Instance Methods

cache() click to toggle source
# File lib/iron_bank/cacheable.rb, line 49
def cache
  IronBank.configuration.cache
end
find(id, force: false) click to toggle source
Calls superclass method
# 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) click to toggle source
Calls superclass method
# 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