Sha256: efc80eacb83736f72907df8ae3ce08eb6758fda53f1ab01da6ab18c78928f7c3

Contents?: true

Size: 756 Bytes

Versions: 3

Compression:

Stored size: 756 Bytes

Contents

require 'singleton'

module Reactor
  module Cache
    class User
      include Singleton

      def get(user_name)
        @cache ||= {}
        # Rails.logger.debug "User:Cache hit: #{hit?(user_name.to_s)} [#{@cache[user_name.to_s].inspect}]"

        key = user_name.to_s
        if hit?(key)
          @cache[key]
        else
          @cache[key] = Reactor::Session::User.new(key)
        end
      end

      def set(user_name, user)
        @cache ||= {}
        @cache[user_name.to_s] = user
      end

      def invalidate(user_name)
        @cache ||= {}
        @cache[user_name.to_s] = nil
      end

      private
      def hit?(user_name)
        key = user_name.to_s
        @cache.key?(key) && !@cache[key].nil?
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
infopark_reactor-1.6.1 lib/reactor/cache/user.rb
infopark_reactor-1.5.2 lib/reactor/cache/user.rb
infopark_reactor-1.5.1 lib/reactor/cache/user.rb