Class: ActionPolicy::LookupChain::NamespaceCache

Inherits:
Object
  • Object
show all
Defined in:
lib/action_policy/lookup_chain.rb

Overview

Cache namespace resolving result for policies.

See Also:

  • benchmarks/namespaced_lookup_cachebenchmarks/namespaced_lookup_cache.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.storeObject (readonly)

Returns the value of attribute store.



22
23
24
# File 'lib/action_policy/lookup_chain.rb', line 22

def store
  @store
end

Class Method Details

.clearObject



30
31
32
# File 'lib/action_policy/lookup_chain.rb', line 30

def clear
  @store = Hash.new { |h, k| h[k] = {} }
end

.fetch(namespace, policy) ⇒ Object



24
25
26
27
28
# File 'lib/action_policy/lookup_chain.rb', line 24

def fetch(namespace, policy)
  return yield unless LookupChain.namespace_cache_enabled?
  return store[namespace][policy] if store[namespace].key?(policy)
  store[namespace][policy] ||= yield
end