Class: AeUsers::PermissionCache

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

Instance Method Summary collapse

Constructor Details

#initializePermissionCache

Returns a new instance of PermissionCache.



70
71
72
# File 'lib/ae_users.rb', line 70

def initialize
  @cache = {}
end

Instance Method Details

#invalidate(person, permissioned, permission) ⇒ Object



86
87
88
89
90
# File 'lib/ae_users.rb', line 86

def invalidate(person, permissioned, permission)
  RAILS_DEFAULT_LOGGER.debug "Permission cache invalidating result for #{person}, #{permissioned}, #{permission}"
  pcache = person_cache(person)
  pcache.delete(pcache_key(permissioned, permission))
end

#invalidate_all(options = {}) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/ae_users.rb', line 92

def invalidate_all(options={})
  if options[:person]
    RAILS_DEFAULT_LOGGER.debug "Permission cache invalidating all results for #{options[:person]}"
    @cache.delete(options[:person])
  elsif options[:permission] and options[:permissioned]
    RAILS_DEFAULT_LOGGER.debug "Permission cache invalidating all results for #{options[:permissioned]}, #{options[:permission]}"
    @cache.each_value do |pcache|
      pcache.delete(pcache_key(options[:permissioned], options[:permission]))
    end
  else
    RAILS_DEFAULT_LOGGER.debug "Permission cache invalidating all results!"
    @cache = {}
  end
end

#permitted?(person, permissioned, permission) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
77
78
79
80
81
82
83
84
# File 'lib/ae_users.rb', line 74

def permitted?(person, permissioned, permission)
  RAILS_DEFAULT_LOGGER.debug "Permission cache looking up result for #{person}, #{permissioned}, #{permission}"
  pcache = person_cache(person)
  key = pcache_key(permissioned, permission)
  unless pcache.has_key?(key)
    RAILS_DEFAULT_LOGGER.debug "Cache miss!  Loading uncached permission."
    pcache[key] = person.uncached_permitted?(permissioned, permission)
  end
  RAILS_DEFAULT_LOGGER.debug "Result is #{pcache[key]}"
  return pcache[key]
end