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
33 34 35 |
# File 'lib/action_policy/behaviours/thread_memoized.rb', line 33 def prepended(base) base.prepend InstanceMethods end |
Instance Method Details
#__policy_thread_memoize__(record, with: nil, namespace: nil) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/action_policy/behaviours/thread_memoized.rb', line 46 def __policy_thread_memoize__(record, with: nil, namespace: nil) record_key = record._policy_cache_key(use_object_id: true) cache_key = "#{namespace}/#{with}/#{record_key}" ActionPolicy::PerThreadCache.fetch(cache_key) { yield } end |