class Reactor::Cache::Permission
Constants
- BACKING_CACHE_EXPIRATION
Public Class Methods
instance()
click to toggle source
# File lib/reactor/cache/permission.rb, line 7 def self.instance self.new end
new()
click to toggle source
# File lib/reactor/cache/permission.rb, line 11 def initialize @@backing_storage ||= ActiveSupport::Cache::MemoryStore.new({ size: 1.megabyte }) end
Public Instance Methods
invalidate(user)
click to toggle source
# File lib/reactor/cache/permission.rb, line 29 def invalidate(user) @@backing_storage.delete(user.to_s) end
lookup(user, key, &block)
click to toggle source
# File lib/reactor/cache/permission.rb, line 15 def lookup(user, key, &block) cache_entry = @@backing_storage.fetch(user.to_s, :expires_in => BACKING_CACHE_EXPIRATION.minutes) do {key => block.call} end if cache_entry.key?(key) cache_entry[key] else result = block.call @@backing_storage.write(user.to_s, cache_entry.merge({key => result}), :expires_in => BACKING_CACHE_EXPIRATION.minutes) result end end