module ActionPolicy::PerThreadCache::Behaviours::ThreadMemoized

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

Public Class Methods

included(base)
Alias for: prepended
prepended(base) click to toggle source
# File lib/action_policy/behaviours/thread_memoized.rb, line 39
def prepended(base)
  base.prepend InstanceMethods
end
Also aliased as: included

Public Instance Methods

__policy_thread_memoize__(record, **options) { || ... } click to toggle source
# File lib/action_policy/behaviours/thread_memoized.rb, line 52
def __policy_thread_memoize__(record, **options)
  cache_key = policy_for_cache_key(record: record, **options)

  ActionPolicy::PerThreadCache.fetch(cache_key) { yield }
end