Sha256: 4df6f2c05d7e60a5c62a380130e1088c0711d1c21aa22022fcc8e6a797df37a5

Contents?: true

Size: 516 Bytes

Versions: 1

Compression:

Stored size: 516 Bytes

Contents

module ActiveSupport
  class ConcurrentHash
    def initialize(hash = {})
      @backup_cache = hash.dup
      @frozen_cache = hash.dup.freeze
      @mutex = Mutex.new
    end

    def []=(k,v)
      @mutex.synchronize { @backup_cache[k] = v }
      @frozen_cache = @backup_cache.dup.freeze
      v
    end

    def [](k)
      if @frozen_cache.key?(k)
        @frozen_cache[k]
      else
        @mutex.synchronize { @backup_cache[k] }
      end
    end

    def empty?
      @backup_cache.empty?
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
recliner-0.0.1 vendor/activesupport/lib/active_support/concurrent_hash.rb