diff options
author | http://jneen.net/ <jneen@jneen.net> | 2017-07-17 20:47:27 +0300 |
---|---|---|
committer | http://jneen.net/ <jneen@jneen.net> | 2017-07-18 00:38:48 +0300 |
commit | fcd3e5d4777efb4b6db2de08347e4db603e1dea2 (patch) | |
tree | 292f8259a3c012bb83d10143d0147f881de550c0 /lib/declarative_policy | |
parent | 45e9d2879122d2aea9494241fac0bd8bf7096446 (diff) |
cache the cache key...
Diffstat (limited to 'lib/declarative_policy')
-rw-r--r-- | lib/declarative_policy/condition.rb | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/declarative_policy/condition.rb b/lib/declarative_policy/condition.rb index 9d7cf6b9726..51c4a8b2bbe 100644 --- a/lib/declarative_policy/condition.rb +++ b/lib/declarative_policy/condition.rb @@ -82,13 +82,14 @@ module DeclarativePolicy # depending on the scope, we may cache only by the user or only by # the subject, resulting in sharing across different policy objects. def cache_key - case @condition.scope - when :normal then "/dp/condition/#{@condition.key}/#{user_key},#{subject_key}" - when :user then "/dp/condition/#{@condition.key}/#{user_key}" - when :subject then "/dp/condition/#{@condition.key}/#{subject_key}" - when :global then "/dp/condition/#{@condition.key}" - else raise 'invalid scope' - end + @cache_key ||= + case @condition.scope + when :normal then "/dp/condition/#{@condition.key}/#{user_key},#{subject_key}" + when :user then "/dp/condition/#{@condition.key}/#{user_key}" + when :subject then "/dp/condition/#{@condition.key}/#{subject_key}" + when :global then "/dp/condition/#{@condition.key}" + else raise 'invalid scope' + end end def user_key |