Sha256: bde65c420460158686176665f2949763c423c8499b45020ef4895bab1f6f569e

Contents?: true

Size: 976 Bytes

Versions: 1

Compression:

Stored size: 976 Bytes

Contents

# frozen_string_literal: true

require 'monitor'

module Dalli
  # Make Dalli threadsafe by using a lock around all
  # public server methods.
  #
  # Dalli::Protocol::Binary.extend(Dalli::Threadsafe)
  #
  module Threadsafe
    def self.extended(obj)
      obj.init_threadsafe
    end

    def request(opcode, *args)
      @lock.synchronize do
        super
      end
    end

    def alive?
      @lock.synchronize do
        super
      end
    end

    def close
      @lock.synchronize do
        super
      end
    end

    def pipeline_response_start
      @lock.synchronize do
        super
      end
    end

    def process_outstanding_pipeline_requests
      @lock.synchronize do
        super
      end
    end

    def pipeline_response_abort
      @lock.synchronize do
        super
      end
    end

    def lock!
      @lock.mon_enter
    end

    def unlock!
      @lock.mon_exit
    end

    def init_threadsafe
      @lock = Monitor.new
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dalli-3.1.0 lib/dalli/options.rb