Method: ActionPolicy::Policy::Cache#cache

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

#cache(*parts, **options) ⇒ Object



71
72
73
74
75
76
77
78
79
80
# File 'lib/action_policy/policy/cache.rb', line 71

def cache(*parts, **options)
  key = cache_key(*parts)
  ActionPolicy.cache_store.then do |store|
    res = store.read(key)
    next res unless res.nil?
    res = yield
    store.write(key, res, options)
    res
  end
end