Method: ActionPolicy::Policy::Cache#apply_with_cache

Defined in:
lib/action_policy/policy/cache.rb

#apply_with_cache(rule) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/action_policy/policy/cache.rb', line 48

def apply_with_cache(rule)
  options = self.class.cached_rules.fetch(rule)
  key = rule_cache_key(rule)

  ActionPolicy.cache_store.then do |store|
    result = store.read(key)
    unless result.nil?
      result.cached!
      next result
    end
    yield.tap do |result|
      store.write(key, result, options)
    end
  end
end