Sha256: 92562a57a104e9c94ce7bdd60c0dde0e81c63aba419f3938a717ecca7c9ae7ba

Contents?: true

Size: 795 Bytes

Versions: 8

Compression:

Stored size: 795 Bytes

Contents

module Reactor
  module Cache
    class Permission
      BACKING_CACHE_EXPIRATION = 5

      def self.instance
        new
      end

      def initialize
        @@backing_storage ||= ActiveSupport::Cache::MemoryStore.new({ size: 1.megabyte })
      end

      def lookup(user, key)
        cache_entry = @@backing_storage.fetch(user.to_s, expires_in: BACKING_CACHE_EXPIRATION.minutes) do
          { key => yield }
        end
        if cache_entry.key?(key)
          cache_entry[key]
        else
          result = yield
          @@backing_storage.write(user.to_s, cache_entry.merge({ key => result }), expires_in: BACKING_CACHE_EXPIRATION.minutes)
          result
        end
      end

      def invalidate(user)
        @@backing_storage.delete(user.to_s)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
infopark_reactor-1.29.1 lib/reactor/cache/permission.rb
infopark_reactor-1.29.0 lib/reactor/cache/permission.rb
infopark_reactor-1.28.0 lib/reactor/cache/permission.rb
infopark_reactor-1.27.0.rc10 lib/reactor/cache/permission.rb
infopark_reactor-1.27.0.rc9 lib/reactor/cache/permission.rb
infopark_reactor-1.27.0.rc8 lib/reactor/cache/permission.rb
infopark_reactor-1.27.0.rc7 lib/reactor/cache/permission.rb
infopark_reactor-1.27.0.rc4 lib/reactor/cache/permission.rb