Sha256: 31bf2b696e3fe44ce5deca164b70d078b5b7991670f30caea11e42719ec8bd77

Contents?: true

Size: 876 Bytes

Versions: 4

Compression:

Stored size: 876 Bytes

Contents

require 'concurrent'

module SplitIoClient
  module Cache
    module Adapters
      class MemoryAdapter < Adapter
        def initialize
          @map = Concurrent::Map.new
        end

        # Map
        def [](key)
          @map[key]
        end

        def []=(key, obj)
          @map[key] = obj
        end

        def initialize_map(key)
          @map[key] = Concurrent::Map.new
        end

        def add_to_map(key, map_key, map_value)
          @map[key].put(map_key, map_value)
        end

        def find_in_map(key, map_key)
          return nil if @map[key].nil?

          @map[key].get(map_key)
        end

        def delete_from_map(key, map_key)
          @map[key].delete(map_key)
        end

        def in_map?(key, map_key)
          return false if @map[key].nil?

          @map[key].key?(map_key)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
splitclient-rb-3.0.3 lib/cache/adapters/memory_adapter.rb
splitclient-rb-3.0.3.pre.rc2 lib/cache/adapters/memory_adapter.rb
splitclient-rb-3.0.3.pre.rc1 lib/cache/adapters/memory_adapter.rb
splitclient-rb-3.0.2 lib/cache/adapters/memory_adapter.rb