Module: ActionPolicy::Behaviours::ThreadMemoized
- Included in:
- Controller
- Defined in:
- lib/action_policy/behaviours/thread_memoized.rb
Overview
Per-thread memoization for policies.
Used by ‘policy_for` to re-use policy object for records.
NOTE: don’t forget to clear thread cache with ActionPolicy::PerThreadCache.clear_all
Defined Under Namespace
Modules: InstanceMethods
Class Method Summary collapse
- .prepended(base) ⇒ Object (also: included)
Instance Method Summary collapse
Class Method Details
.prepended(base) ⇒ Object Also known as: included
39 40 41 |
# File 'lib/action_policy/behaviours/thread_memoized.rb', line 39 def prepended(base) base.prepend InstanceMethods end |
Instance Method Details
#__policy_thread_memoize__(record, **options) ⇒ Object
52 53 54 55 56 |
# File 'lib/action_policy/behaviours/thread_memoized.rb', line 52 def __policy_thread_memoize__(record, **) cache_key = policy_for_cache_key(record: record, **) ActionPolicy::PerThreadCache.fetch(cache_key) { yield } end |