class Dalli::Protocol::ResponseBuffer

Manages the buffer for responses from memcached.

Public Class Methods

new(io_source, response_processor) click to toggle source
# File lib/dalli/protocol/response_buffer.rb, line 11
def initialize(io_source, response_processor)
  @io_source = io_source
  @response_processor = response_processor
  @buffer = nil
end

Public Instance Methods

advance(bytes_to_advance) click to toggle source

Advances the internal response buffer by bytes_to_advance bytes. The

# File lib/dalli/protocol/response_buffer.rb, line 31
def advance(bytes_to_advance)
  return unless bytes_to_advance.positive?

  @buffer = @buffer.byteslice(bytes_to_advance..-1)
end
clear() click to toggle source

Clear the internal response buffer

# File lib/dalli/protocol/response_buffer.rb, line 44
def clear
  @buffer = nil
end
in_progress?() click to toggle source
# File lib/dalli/protocol/response_buffer.rb, line 48
def in_progress?
  !@buffer.nil?
end
process_single_getk_response() click to toggle source

Attempts to process a single response from the buffer. Starts by advancing the buffer to the specified start position

# File lib/dalli/protocol/response_buffer.rb, line 23
def process_single_getk_response
  bytes, status, cas, key, value = @response_processor.getk_response_from_buffer(@buffer)
  advance(bytes)
  [status, cas, key, value]
end
read() click to toggle source
# File lib/dalli/protocol/response_buffer.rb, line 17
def read
  @buffer << @io_source.read_nonblock
end
reset() click to toggle source

Resets the internal buffer to an empty state, so that we're ready to read pipelined responses

# File lib/dalli/protocol/response_buffer.rb, line 39
def reset
  @buffer = ''.b
end